- Timestamp:
- Feb 9, 2009 10:39:58 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c
r2438 r2444 68 68 struct conf_port 69 69 { 70 SLOT_TYPE slot; /**< Array of listeners. */ 70 71 pj_str_t name; /**< Port name. */ 71 72 pjmedia_port *port; /**< get_frame() and put_frame() */ … … 77 78 78 79 /* Shortcut for port info. */ 79 unsigned clock_rate; /**< Port's clock rate. */ 80 unsigned samples_per_frame; /**< Port's samples per frame. */ 81 unsigned channel_count; /**< Port's channel count. */ 80 pjmedia_port_info *info; 82 81 83 82 /* Calculated signal levels: */ … … 118 117 pj_mutex_t *mutex; /**< Conference mutex. */ 119 118 struct conf_port **ports; /**< Array of ports. */ 120 unsigned clock_rate; /**< Sampling rate. */121 unsigned channel_count;/**< Number of channels (1=mono). */122 unsigned samples_per_frame; /**< Samples per frame. */123 unsigned bits_per_sample; /**< Bits per sample. */124 119 pj_uint8_t buf[BUFFER_SIZE]; /**< Common buffer. */ 125 120 }; … … 146 141 pjmedia_frame *f; 147 142 143 PJ_ASSERT_RETURN(pool && conf && port && name && p_conf_port, PJ_EINVAL); 144 148 145 /* Create port. */ 149 146 conf_port = PJ_POOL_ZALLOC_T(pool, struct conf_port); … … 163 160 164 161 /* Save some port's infos, for convenience. */ 165 if (port) { 166 conf_port->port = port; 167 conf_port->clock_rate = port->info.clock_rate; 168 conf_port->samples_per_frame = port->info.samples_per_frame; 169 conf_port->channel_count = port->info.channel_count; 170 } else { 171 conf_port->port = NULL; 172 conf_port->clock_rate = conf->clock_rate; 173 conf_port->samples_per_frame = conf->samples_per_frame; 174 conf_port->channel_count = conf->channel_count; 175 } 162 conf_port->port = port; 163 conf_port->info = &port->info; 176 164 177 165 /* Init pjmedia_frame structure in the TX buffer. */ … … 196 184 197 185 198 status = create_conf_port(pool, conf, NULL, &name, &conf_port);186 status = create_conf_port(pool, conf, conf->master_port, &name, &conf_port); 199 187 if (status != PJ_SUCCESS) 200 188 return status; … … 206 194 pjmedia_snd_stream *strm; 207 195 pjmedia_snd_stream_info si; 196 pjmedia_port_info *master_port_info = (pjmedia_port_info*) 197 &conf->master_port->info; 208 198 209 199 /* … … 212 202 */ 213 203 if (conf->options & PJMEDIA_CONF_NO_MIC) { 214 status = pjmedia_snd_port_create_player(pool, -1, conf->clock_rate, 215 conf->channel_count, 216 conf->samples_per_frame, 217 conf->bits_per_sample, 218 0, /* options */ 219 &conf->snd_dev_port); 204 status = pjmedia_snd_port_create_player( 205 pool, -1, 206 master_port_info->clock_rate, 207 master_port_info->channel_count, 208 master_port_info->samples_per_frame, 209 master_port_info->bits_per_sample, 210 0, /* options */ 211 &conf->snd_dev_port); 220 212 221 213 } else { 222 status = pjmedia_snd_port_create( pool, -1, -1, conf->clock_rate, 223 conf->channel_count, 224 conf->samples_per_frame, 225 conf->bits_per_sample, 226 0, /* Options */ 227 &conf->snd_dev_port); 228 214 status = pjmedia_snd_port_create( 215 pool, -1, -1, 216 master_port_info->clock_rate, 217 master_port_info->channel_count, 218 master_port_info->samples_per_frame, 219 master_port_info->bits_per_sample, 220 0, /* Options */ 221 &conf->snd_dev_port); 229 222 } 230 223 … … 246 239 247 240 /* Add the port to the bridge */ 241 conf_port->slot = 0; 248 242 conf->ports[0] = conf_port; 249 243 conf->port_cnt++; … … 286 280 conf->options = options; 287 281 conf->max_ports = max_ports; 288 conf->clock_rate = clock_rate;289 conf->channel_count = channel_count;290 conf->samples_per_frame = samples_per_frame;291 conf->bits_per_sample = bits_per_sample;292 293 282 294 283 /* Create and initialize the master port interface. */ … … 425 414 conf->ports[0]->name.slen = len; 426 415 427 if (conf->master_port) 428 conf->master_port->info.name = conf->ports[0]->name; 416 conf->master_port->info.name = conf->ports[0]->name; 429 417 430 418 return PJ_SUCCESS; … … 445 433 446 434 PJ_ASSERT_RETURN(conf && pool && strm_port, PJ_EINVAL); 435 /* 447 436 PJ_ASSERT_RETURN(conf->clock_rate == strm_port->info.clock_rate, 448 437 PJMEDIA_ENCCLOCKRATE); … … 451 440 PJ_ASSERT_RETURN(conf->bits_per_sample == strm_port->info.bits_per_sample, 452 441 PJMEDIA_ENCBITS); 442 */ 453 443 454 444 /* Port's samples per frame should be equal to or multiplication of 455 445 * conference's samples per frame. 456 446 */ 447 /* 448 Not sure if this is needed! 457 449 PJ_ASSERT_RETURN((conf->samples_per_frame % 458 450 strm_port->info.samples_per_frame==0) || … … 460 452 conf->samples_per_frame==0), 461 453 PJMEDIA_ENCSAMPLESPFRAME); 454 */ 462 455 463 456 /* If port_name is not specified, use the port's name */ … … 489 482 490 483 /* Put the port. */ 484 conf_port->slot = index; 491 485 conf->ports[index] = conf_port; 492 486 conf->port_cnt++; … … 589 583 dst_port = conf->ports[sink_slot]; 590 584 585 /* Source and sink ptime must be equal or a multiplication factor. */ 586 if ((src_port->info->samples_per_frame % 587 dst_port->info->samples_per_frame != 0) && 588 (dst_port->info->samples_per_frame % 589 src_port->info->samples_per_frame != 0)) 590 { 591 pj_mutex_unlock(conf->mutex); 592 return PJMEDIA_ENCSAMPLESPFRAME; 593 } 594 591 595 /* Check if source and sink has compatible format */ 592 596 if (src_slot != 0 && sink_slot != 0 && … … 678 682 --src_port->listener_cnt; 679 683 --dst_port->transmitter_cnt; 684 685 /* Clean up sink TX buffer. */ 686 pj_bzero(dst_port->tx_buf, sizeof(pjmedia_frame_ext)); 680 687 681 688 PJ_LOG(4,(THIS_FILE, … … 777 784 pj_assert(conf->connect_cnt > 0); 778 785 --conf->connect_cnt; 786 787 /* Clean up TX buffer. */ 788 pj_bzero(dst_port->tx_buf, sizeof(pjmedia_frame_ext)); 779 789 } 780 790 … … 842 852 info->listener_cnt = conf_port->listener_cnt; 843 853 info->listener_slots = conf_port->listener_slots; 844 info->clock_rate = conf_port->clock_rate; 845 info->channel_count = conf_port->channel_count; 846 info->samples_per_frame = conf_port->samples_per_frame; 847 info->bits_per_sample = conf->bits_per_sample; 848 info->format = slot? conf_port->port->info.format : 849 conf->master_port->info.format; 854 info->clock_rate = conf_port->info->clock_rate; 855 info->channel_count = conf_port->info->channel_count; 856 info->samples_per_frame = conf_port->info->samples_per_frame; 857 info->bits_per_sample = conf_port->info->bits_per_sample; 858 info->format = conf_port->port->info.format; 850 859 851 860 return PJ_SUCCESS; … … 991 1000 * samples per frame. 992 1001 */ 993 if (f_dst->samples_cnt == cport_dst-> samples_per_frame)1002 if (f_dst->samples_cnt == cport_dst->info->samples_per_frame) 994 1003 { 995 if (cport_dst-> port) {1004 if (cport_dst->slot) { 996 1005 pjmedia_port_put_frame(cport_dst->port, 997 1006 (pjmedia_frame*)f_dst); … … 1004 1013 /* Update TX timestamp. */ 1005 1014 pj_add_timestamp32(&cport_dst->ts_tx, 1006 cport_dst->samples_per_frame); 1007 1015 cport_dst->info->samples_per_frame); 1008 1016 } 1009 1017 } … … 1020 1028 /* Copy frame to listener's TX buffer. */ 1021 1029 nsamples_to_copy = f_end - f_start; 1022 nsamples_req = cport_dst->samples_per_frame - (frm_dst->size>>1); 1030 nsamples_req = cport_dst->info->samples_per_frame - 1031 (frm_dst->size>>1); 1023 1032 if (nsamples_to_copy > nsamples_req) 1024 1033 nsamples_to_copy = nsamples_req; 1034 1025 1035 pjmedia_copy_samples((pj_int16_t*)frm_dst->buf + (frm_dst->size>>1), 1026 1036 f_start, … … 1033 1043 * samples per frame. 1034 1044 */ 1035 if ((frm_dst->size >> 1) == cport_dst-> samples_per_frame)1045 if ((frm_dst->size >> 1) == cport_dst->info->samples_per_frame) 1036 1046 { 1037 if (cport_dst-> port) {1047 if (cport_dst->slot) { 1038 1048 pjmedia_port_put_frame(cport_dst->port, frm_dst); 1039 1049 … … 1044 1054 /* Update TX timestamp. */ 1045 1055 pj_add_timestamp32(&cport_dst->ts_tx, 1046 cport_dst-> samples_per_frame);1056 cport_dst->info->samples_per_frame); 1047 1057 } 1048 1058 } … … 1059 1069 if (frm_dst->size != 0) { 1060 1070 pjmedia_zero_samples((pj_int16_t*)frm_dst->buf, 1061 cport_dst-> samples_per_frame -1071 cport_dst->info->samples_per_frame - 1062 1072 (frm_dst->size>>1)); 1063 1073 1064 1074 frm_dst->type = PJMEDIA_FRAME_TYPE_AUDIO; 1065 frm_dst->size = cport_dst-> samples_per_frame << 1;1066 if (cport_dst-> port) {1075 frm_dst->size = cport_dst->info->samples_per_frame << 1; 1076 if (cport_dst->slot) { 1067 1077 pjmedia_port_put_frame(cport_dst->port, frm_dst); 1068 1078 … … 1073 1083 /* Update TX timestamp. */ 1074 1084 pj_add_timestamp32(&cport_dst->ts_tx, 1075 cport_dst-> samples_per_frame);1085 cport_dst->info->samples_per_frame); 1076 1086 } 1077 1087 } else { … … 1081 1091 frm_dst->type = PJMEDIA_FRAME_TYPE_EXTENDED; 1082 1092 pjmedia_frame_ext_append_subframe(f_dst, NULL, 0, (pj_uint16_t) 1083 (cport_dst->samples_per_frame- 1084 f_dst->samples_cnt)); 1085 if (cport_dst->port) { 1093 (cport_dst->info->samples_per_frame - f_dst->samples_cnt)); 1094 if (cport_dst->slot) { 1086 1095 pjmedia_port_put_frame(cport_dst->port, frm_dst); 1087 1096 … … 1093 1102 /* Update TX timestamp. */ 1094 1103 pj_add_timestamp32(&cport_dst->ts_tx, 1095 cport_dst-> samples_per_frame);1104 cport_dst->info->samples_per_frame); 1096 1105 } 1097 1106 } … … 1103 1112 frm_dst->type = PJMEDIA_FRAME_TYPE_NONE; 1104 1113 frm_dst->timestamp = cport_dst->ts_tx; 1105 if (cport_dst-> port)1114 if (cport_dst->slot) 1106 1115 pjmedia_port_put_frame(cport_dst->port, frm_dst); 1107 1116 1108 1117 /* Update TX timestamp. */ 1109 pj_add_timestamp32(&cport_dst->ts_tx, cport_dst-> samples_per_frame);1118 pj_add_timestamp32(&cport_dst->ts_tx, cport_dst->info->samples_per_frame); 1110 1119 } 1111 1120 } … … 1144 1153 1145 1154 /* Update clock of the port. */ 1146 pj_add_timestamp32(&cport->ts_clock, conf->samples_per_frame); 1155 pj_add_timestamp32(&cport->ts_clock, 1156 conf->master_port->info.samples_per_frame); 1147 1157 1148 1158 /* Skip if we're not allowed to receive from this port or … … 1166 1176 pj_int32_t level; 1167 1177 1168 pj_add_timestamp32(&cport->ts_rx, cport-> samples_per_frame);1178 pj_add_timestamp32(&cport->ts_rx, cport->info->samples_per_frame); 1169 1179 1170 1180 f->buf = &conf->buf[sizeof(pjmedia_frame)]; … … 1200 1210 if (listener->tx_setting == PJMEDIA_PORT_DISABLE) { 1201 1211 pj_add_timestamp32(&listener->ts_tx, 1202 listener-> samples_per_frame);1212 listener->info->samples_per_frame); 1203 1213 listener->tx_level = 0; 1204 1214 continue; … … 1250 1260 1251 1261 pjmedia_port_put_frame(cport->port, &tmp_f); 1252 pj_add_timestamp32(&cport->ts_tx, cport-> samples_per_frame);1262 pj_add_timestamp32(&cport->ts_tx, cport->info->samples_per_frame); 1253 1263 } 1254 1264 } … … 1269 1279 pj_uint16_t samples_per_subframe; 1270 1280 1271 if (f_src_->samples_cnt < this_cport-> samples_per_frame) {1281 if (f_src_->samples_cnt < this_cport->info->samples_per_frame) { 1272 1282 pj_bzero(this_cport->tx_buf, sizeof(pjmedia_frame_ext)); 1273 1283 frame->type = PJMEDIA_FRAME_TYPE_NONE; … … 1281 1291 1282 1292 1283 while (f_dst->samples_cnt < this_cport-> samples_per_frame) {1293 while (f_dst->samples_cnt < this_cport->info->samples_per_frame) { 1284 1294 sf = pjmedia_frame_ext_get_subframe(f_src_, i++); 1285 1295 pj_assert(sf); … … 1292 1302 1293 1303 } else if (f_src->type == PJMEDIA_FRAME_TYPE_AUDIO) { 1294 if ((f_src->size>>1) < this_cport-> samples_per_frame) {1304 if ((f_src->size>>1) < this_cport->info->samples_per_frame) { 1295 1305 pj_bzero(this_cport->tx_buf, sizeof(pjmedia_frame_ext)); 1296 1306 frame->type = PJMEDIA_FRAME_TYPE_NONE; … … 1300 1310 pjmedia_copy_samples((pj_int16_t*)frame->buf, 1301 1311 (pj_int16_t*)f_src->buf, 1302 this_cport-> samples_per_frame);1303 frame->size = this_cport-> samples_per_frame << 1;1312 this_cport->info->samples_per_frame); 1313 frame->size = this_cport->info->samples_per_frame << 1; 1304 1314 1305 1315 /* Shift left TX buffer. */ … … 1308 1318 pjmedia_move_samples((pj_int16_t*)f_src->buf, 1309 1319 (pj_int16_t*)f_src->buf + 1310 this_cport-> samples_per_frame,1320 this_cport->info->samples_per_frame, 1311 1321 f_src->size >> 1); 1312 1322 } else { /* PJMEDIA_FRAME_TYPE_NONE */ … … 1334 1344 pj_int32_t level; 1335 1345 1336 pj_add_timestamp32(&cport->ts_rx, cport-> samples_per_frame);1346 pj_add_timestamp32(&cport->ts_rx, cport->info->samples_per_frame); 1337 1347 1338 1348 /* Skip if this port is muted/disabled. */ … … 1373 1383 if (listener->tx_setting == PJMEDIA_PORT_DISABLE) { 1374 1384 pj_add_timestamp32(&listener->ts_tx, 1375 listener-> samples_per_frame);1385 listener->info->samples_per_frame); 1376 1386 listener->tx_level = 0; 1377 1387 continue; … … 1381 1391 if (listener == cport) { 1382 1392 pj_add_timestamp32(&listener->ts_tx, 1383 listener-> samples_per_frame);1393 listener->info->samples_per_frame); 1384 1394 listener->tx_level = 0; 1385 1395 continue;
Note: See TracChangeset
for help on using the changeset viewer.