- Timestamp:
- Feb 18, 2009 1:55:03 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/pa_dev.c
r2458 r2459 27 27 28 28 #define THIS_FILE "pa_dev.c" 29 #define DRIVER_NAME " portaudio"29 #define DRIVER_NAME "PA" 30 30 31 31 struct pa_aud_factory … … 102 102 static unsigned pa_get_dev_count(pjmedia_aud_dev_factory *f); 103 103 static pj_status_t pa_get_dev_info(pjmedia_aud_dev_factory *f, 104 pjmedia_aud_dev_id id,104 unsigned index, 105 105 pjmedia_aud_dev_info *info); 106 106 static pj_status_t pa_default_param(pjmedia_aud_dev_factory *f, 107 pjmedia_aud_dev_id id,107 unsigned index, 108 108 pjmedia_aud_dev_param *param); 109 109 static pj_status_t pa_create_stream(pjmedia_aud_dev_factory *f, … … 190 190 ++stream->overflow; 191 191 192 stream->rec_timestamp.u64 += frameCount;193 194 192 /* Calculate number of samples we've got */ 195 193 nsamples = frameCount * stream->channel_count + stream->rec_buf_count; … … 202 200 if (stream->rec_buf_count) { 203 201 unsigned chunk_count = 0; 202 pjmedia_frame frame; 204 203 205 204 chunk_count = stream->samples_per_frame - stream->rec_buf_count; 206 205 pjmedia_copy_samples(stream->rec_buf + stream->rec_buf_count, 207 206 (pj_int16_t*)input, chunk_count); 208 status = (*stream->rec_cb)(stream->user_data, 209 &stream->rec_timestamp, 210 (void*) stream->rec_buf, 211 stream->samples_per_frame * 212 stream->bytes_per_sample); 207 208 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 209 frame.buf = (void*) stream->rec_buf; 210 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 211 frame.timestamp.u64 = stream->rec_timestamp.u64; 212 frame.bit_info = 0; 213 214 status = (*stream->rec_cb)(stream->user_data, &frame); 213 215 214 216 input = (pj_int16_t*) input + chunk_count; 215 217 nsamples -= stream->samples_per_frame; 216 218 stream->rec_buf_count = 0; 219 stream->rec_timestamp.u64 += stream->samples_per_frame / 220 stream->channel_count; 217 221 } 218 222 219 223 /* Give all frames we have */ 220 224 while (nsamples >= stream->samples_per_frame && status == 0) { 221 status = (*stream->rec_cb)(stream->user_data, 222 &stream->rec_timestamp, 223 (void*) input, 224 stream->samples_per_frame * 225 stream->bytes_per_sample); 225 pjmedia_frame frame; 226 227 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 228 frame.buf = (void*) input; 229 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 230 frame.timestamp.u64 = stream->rec_timestamp.u64; 231 frame.bit_info = 0; 232 233 status = (*stream->rec_cb)(stream->user_data, &frame); 234 226 235 input = (pj_int16_t*) input + stream->samples_per_frame; 227 236 nsamples -= stream->samples_per_frame; 237 stream->rec_timestamp.u64 += stream->samples_per_frame / 238 stream->channel_count; 228 239 } 229 240 … … 291 302 ++stream->overflow; 292 303 293 stream->play_timestamp.u64 += frameCount;294 304 295 305 /* Check if any buffered samples */ … … 319 329 while (nsamples_req && status == 0) { 320 330 if (nsamples_req >= stream->samples_per_frame) { 321 status = (*stream->play_cb)(stream->user_data, 322 &stream->play_timestamp, 323 output, 324 stream->samples_per_frame * 325 stream->bytes_per_sample); 331 pjmedia_frame frame; 332 333 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 334 frame.buf = output; 335 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 336 frame.timestamp.u64 = stream->play_timestamp.u64; 337 frame.bit_info = 0; 338 339 status = (*stream->play_cb)(stream->user_data, &frame); 340 if (status != PJ_SUCCESS) 341 goto on_break; 342 343 if (frame.type != PJMEDIA_FRAME_TYPE_AUDIO) 344 pj_bzero(frame.buf, frame.size); 345 326 346 nsamples_req -= stream->samples_per_frame; 327 347 output = (pj_int16_t*)output + stream->samples_per_frame; 328 348 } else { 329 status = (*stream->play_cb)(stream->user_data, 330 &stream->play_timestamp, 331 stream->play_buf, 332 stream->samples_per_frame * 333 stream->bytes_per_sample); 349 pjmedia_frame frame; 350 351 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 352 frame.buf = stream->play_buf; 353 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 354 frame.timestamp.u64 = stream->play_timestamp.u64; 355 frame.bit_info = 0; 356 357 status = (*stream->play_cb)(stream->user_data, &frame); 358 if (status != PJ_SUCCESS) 359 goto on_break; 360 361 if (frame.type != PJMEDIA_FRAME_TYPE_AUDIO) 362 pj_bzero(frame.buf, frame.size); 363 334 364 pjmedia_copy_samples((pj_int16_t*)output, stream->play_buf, 335 365 nsamples_req); … … 340 370 nsamples_req = 0; 341 371 } 372 373 stream->play_timestamp.u64 += stream->samples_per_frame / 374 stream->channel_count; 342 375 } 343 376 … … 453 486 /* API: Get device info. */ 454 487 static pj_status_t pa_get_dev_info(pjmedia_aud_dev_factory *f, 455 pjmedia_aud_dev_id id,488 unsigned index, 456 489 pjmedia_aud_dev_info *info) 457 490 { … … 460 493 PJ_UNUSED_ARG(f); 461 494 462 pa_info = Pa_GetDeviceInfo(i d);495 pa_info = Pa_GetDeviceInfo(index); 463 496 if (!pa_info) 464 497 return PJMEDIA_EAUD_INVDEV; … … 481 514 /* API: fill in with default parameter. */ 482 515 static pj_status_t pa_default_param(pjmedia_aud_dev_factory *f, 483 pjmedia_aud_dev_id id,516 unsigned index, 484 517 pjmedia_aud_dev_param *param) 485 518 { … … 489 522 PJ_UNUSED_ARG(f); 490 523 491 status = p jmedia_aud_dev_get_info(id, &adi);524 status = pa_get_dev_info(f, index, &adi); 492 525 if (status != PJ_SUCCESS) 493 526 return status; … … 496 529 if (adi.input_count && adi.output_count) { 497 530 param->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 498 param->rec_id = i d;499 param->play_id = i d;531 param->rec_id = index; 532 param->play_id = index; 500 533 } else if (adi.input_count) { 501 534 param->dir = PJMEDIA_DIR_CAPTURE; 502 param->rec_id = i d;535 param->rec_id = index; 503 536 param->play_id = PJMEDIA_AUD_DEV_DEFAULT_ID; 504 537 } else if (adi.output_count) { 505 538 param->dir = PJMEDIA_DIR_PLAYBACK; 506 param->play_id = i d;539 param->play_id = index; 507 540 param->rec_id = PJMEDIA_AUD_DEV_DEFAULT_ID; 508 541 } else { … … 1080 1113 pi->flags |= PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY; 1081 1114 pi->input_latency_ms = (unsigned)(paRecSI ? paRecSI->inputLatency * 1082 paRecSI->sampleRate: 0);1115 1000 : 0); 1083 1116 } 1084 1117 if (paPlaySI) { 1085 1118 pi->flags |= PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY; 1086 1119 pi->output_latency_ms = (unsigned)(paPlaySI? paPlaySI->outputLatency * 1087 paPlaySI->sampleRate: 0);1120 1000 : 0); 1088 1121 } 1089 1122 … … 1106 1139 return PJ_EINVALIDOP; 1107 1140 1108 *(unsigned*)pval = (unsigned)(si->inputLatency * si->sampleRate);1141 *(unsigned*)pval = (unsigned)(si->inputLatency * 1000); 1109 1142 return PJ_SUCCESS; 1110 1143 } else if (cap==PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY && strm->play_strm) { … … 1113 1146 return PJ_EINVALIDOP; 1114 1147 1115 *(unsigned*)pval = (unsigned)(si->outputLatency * si->sampleRate);1148 *(unsigned*)pval = (unsigned)(si->outputLatency * 1000); 1116 1149 return PJ_SUCCESS; 1117 1150 } else {
Note: See TracChangeset
for help on using the changeset viewer.