Changeset 744
- Timestamp:
- Sep 27, 2006 10:49:55 PM (18 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/sound.h
r645 r744 74 74 unsigned default_samples_per_sec;/**< Default sampling rate. */ 75 75 } pjmedia_snd_dev_info; 76 77 /** 78 * Stream information, can be retrieved from a live stream by calling 79 * #pjmedia_snd_stream_get_info(). 80 */ 81 typedef struct pjmedia_snd_stream_info 82 { 83 pjmedia_dir dir; /**< Stream direction. */ 84 int play_id; /**< Playback dev id, or -1 for rec only*/ 85 int rec_id; /**< Capture dev id, or -1 for play only*/ 86 unsigned clock_rate; /**< Actual clock rate. */ 87 unsigned channel_count; /**< Number of channels. */ 88 unsigned samples_per_frame; /**< Samples per frame. */ 89 unsigned bits_per_sample; /**< Bits per sample. */ 90 unsigned rec_latency; /**< Record latency, in samples. */ 91 unsigned play_latency; /**< Playback latency, in samples. */ 92 } pjmedia_snd_stream_info; 93 76 94 77 95 /** … … 233 251 234 252 /** 253 * Get information about live stream. 254 * 255 * @param strm The stream to be queried. 256 * @param i Pointer to stream information to be filled up with 257 * information about the stream. 258 * 259 * @return PJ_SUCCESS on success or the appropriate error code. 260 */ 261 PJ_DECL(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm, 262 pjmedia_snd_stream_info *pi); 263 264 265 /** 235 266 * Start the stream. 236 267 * -
pjproject/trunk/pjmedia/src/pjmedia/dsound.c
r732 r744 90 90 { 91 91 pjmedia_dir dir; /**< Sound direction. */ 92 int play_id; /**< Playback dev id. */ 93 int rec_id; /**< Recording dev id. */ 92 94 pj_pool_t *pool; /**< Memory pool. */ 93 95 … … 102 104 unsigned clock_rate; /**< Clock rate. */ 103 105 unsigned samples_per_frame; /**< Samples per frame. */ 106 unsigned bits_per_sample; /**< Bits per sample. */ 107 unsigned channel_count; /**< Channel count. */ 104 108 105 109 pj_thread_t *thread; /**< Thread handle. */ … … 720 724 strm = pj_pool_zalloc(pool, sizeof(pjmedia_snd_stream)); 721 725 strm->dir = dir; 726 strm->play_id = play_id; 727 strm->rec_id = rec_id; 722 728 strm->pool = pool; 723 729 strm->rec_cb = rec_cb; … … 726 732 strm->clock_rate = clock_rate; 727 733 strm->samples_per_frame = samples_per_frame; 734 strm->bits_per_sample = bits_per_sample; 735 strm->channel_count = channel_count; 728 736 strm->buffer = pj_pool_alloc(pool, samples_per_frame * BYTES_PER_SAMPLE); 729 737 if (!strm->buffer) { … … 828 836 829 837 /* 838 * Get stream info. 839 */ 840 PJ_DEF(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm, 841 pjmedia_snd_stream_info *pi) 842 { 843 844 PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL); 845 846 pj_bzero(pi, sizeof(*pi)); 847 pi->dir = strm->dir; 848 pi->play_id = strm->play_id; 849 pi->rec_id = strm->rec_id; 850 pi->clock_rate = strm->clock_rate; 851 pi->channel_count = strm->channel_count; 852 pi->samples_per_frame = strm->samples_per_frame; 853 pi->bits_per_sample = strm->bits_per_sample; 854 pi->rec_latency = 0; 855 pi->play_latency = 0; 856 857 return PJ_SUCCESS; 858 } 859 860 861 /* 830 862 * Start stream. 831 863 */ -
pjproject/trunk/pjmedia/src/pjmedia/pasound.c
r645 r744 19 19 #include <pjmedia/sound.h> 20 20 #include <pjmedia/errno.h> 21 #include <pj/assert.h> 21 22 #include <pj/log.h> 22 23 #include <pj/os.h> … … 43 44 pj_str_t name; 44 45 pjmedia_dir dir; 46 int play_id; 47 int rec_id; 45 48 int bytes_per_sample; 46 49 pj_uint32_t samples_per_sec; 50 unsigned samples_per_frame; 47 51 int channel_count; 48 52 … … 242 246 const PaDeviceInfo *paDevInfo = NULL; 243 247 const PaHostApiInfo *paHostApiInfo = NULL; 244 unsigned paFrames; 248 unsigned paFrames, paRate, paLatency; 249 const PaStreamInfo *paSI; 245 250 PaError err; 246 251 … … 281 286 pj_strdup2_with_null(pool, &stream->name, paDevInfo->name); 282 287 stream->dir = PJMEDIA_DIR_CAPTURE; 288 stream->rec_id = index; 289 stream->play_id = -1; 283 290 stream->user_data = user_data; 284 291 stream->samples_per_sec = clock_rate; 292 stream->samples_per_frame = samples_per_frame; 285 293 stream->bytes_per_sample = bits_per_sample / 8; 286 294 stream->channel_count = channel_count; … … 307 315 } 308 316 309 PJ_LOG(5,(THIS_FILE, "%s opening device %s (%s) for recording, sample " 317 paSI = Pa_GetStreamInfo(stream->stream); 318 paRate = (unsigned)paSI->sampleRate; 319 paLatency = (unsigned)(paSI->inputLatency * 1000); 320 321 PJ_LOG(5,(THIS_FILE, "Opened device %s (%s) for recording, sample " 310 322 "rate=%d, ch=%d, " 311 "bits=%d, %d samples per frame", 312 (err==0 ? "Success" : "Error"), 323 "bits=%d, %d samples per frame, latency=%d ms", 313 324 paDevInfo->name, paHostApiInfo->name, 314 clock_rate, channel_count, 315 bits_per_sample, samples_per_frame)); 325 paSI->sampleRate, channel_count, 326 bits_per_sample, samples_per_frame, 327 paLatency)); 316 328 317 329 *p_snd_strm = stream; … … 335 347 const PaDeviceInfo *paDevInfo = NULL; 336 348 const PaHostApiInfo *paHostApiInfo = NULL; 337 unsigned paFrames; 349 const PaStreamInfo *paSI; 350 unsigned paFrames, paRate, paLatency; 338 351 PaError err; 339 352 … … 374 387 pj_strdup2_with_null(pool, &stream->name, paDevInfo->name); 375 388 stream->dir = stream->dir = PJMEDIA_DIR_PLAYBACK; 389 stream->play_id = index; 390 stream->rec_id = -1; 376 391 stream->user_data = user_data; 377 392 stream->samples_per_sec = clock_rate; 393 stream->samples_per_frame = samples_per_frame; 378 394 stream->bytes_per_sample = bits_per_sample / 8; 379 395 stream->channel_count = channel_count; … … 400 416 } 401 417 402 PJ_LOG(5,(THIS_FILE, "%s opening device %d: %s(%s) for playing, sample rate=%d" 418 paSI = Pa_GetStreamInfo(stream->stream); 419 paRate = (unsigned)(paSI->sampleRate); 420 paLatency = (unsigned)(paSI->outputLatency * 1000); 421 422 PJ_LOG(5,(THIS_FILE, "Opened device %d: %s(%s) for playing, sample rate=%d" 403 423 ", ch=%d, " 404 "bits=%d, %d samples per frame", 405 (err==0 ? "Success" : "Error"), 424 "bits=%d, %d samples per frame, latency=%d ms", 406 425 index, paDevInfo->name, paHostApiInfo->name, 407 clock_rate, channel_count,408 bits_per_sample, samples_per_frame ));426 paRate, channel_count, 427 bits_per_sample, samples_per_frame, paLatency)); 409 428 410 429 *p_snd_strm = stream; … … 437 456 const PaHostApiInfo *paRecHostApiInfo = NULL; 438 457 const PaHostApiInfo *paPlayHostApiInfo = NULL; 439 unsigned paFrames; 458 const PaStreamInfo *paSI; 459 unsigned paFrames, paRate, paInputLatency, paOutputLatency; 440 460 PaError err; 441 461 … … 495 515 pj_strdup2_with_null(pool, &stream->name, paRecDevInfo->name); 496 516 stream->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 517 stream->play_id = play_id; 518 stream->rec_id = rec_id; 497 519 stream->user_data = user_data; 498 520 stream->samples_per_sec = clock_rate; 521 stream->samples_per_frame = samples_per_frame; 499 522 stream->bytes_per_sample = bits_per_sample / 8; 500 523 stream->channel_count = channel_count; … … 531 554 } 532 555 533 PJ_LOG(5,(THIS_FILE, "%s opening device %s(%s)/%s(%s) for recording and " 556 paSI = Pa_GetStreamInfo(stream->stream); 557 paRate = (unsigned)(paSI->sampleRate); 558 paInputLatency = (unsigned)(paSI->inputLatency * 1000); 559 paOutputLatency = (unsigned)(paSI->outputLatency * 1000); 560 561 PJ_LOG(5,(THIS_FILE, "Opened device %s(%s)/%s(%s) for recording and " 534 562 "playback, sample rate=%d, ch=%d, " 535 "bits=%d, %d samples per frame ",536 (err==0 ? "Success" : "Error"),563 "bits=%d, %d samples per frame, input latency=%d ms, " 564 "output latency=%d ms", 537 565 paRecDevInfo->name, paRecHostApiInfo->name, 538 566 paPlayDevInfo->name, paPlayHostApiInfo->name, 539 clock_rate, channel_count, 540 bits_per_sample, samples_per_frame)); 567 paRate, channel_count, 568 bits_per_sample, samples_per_frame, 569 paInputLatency, paOutputLatency)); 541 570 542 571 *p_snd_strm = stream; … … 545 574 return PJ_SUCCESS; 546 575 } 576 577 578 /* 579 * Get stream info. 580 */ 581 PJ_DEF(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm, 582 pjmedia_snd_stream_info *pi) 583 { 584 const PaStreamInfo *paSI; 585 586 PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL); 587 PJ_ASSERT_RETURN(strm->stream, PJ_EINVALIDOP); 588 589 paSI = Pa_GetStreamInfo(strm->stream); 590 591 pj_bzero(pi, sizeof(*pi)); 592 pi->dir = strm->dir; 593 pi->play_id = strm->play_id; 594 pi->rec_id = strm->rec_id; 595 pi->clock_rate = (unsigned)(paSI->sampleRate); 596 pi->channel_count = strm->channel_count; 597 pi->samples_per_frame = strm->samples_per_frame; 598 pi->bits_per_sample = strm->bytes_per_sample * 8; 599 pi->rec_latency = (unsigned)(paSI->inputLatency * paSI->sampleRate); 600 pi->play_latency = (unsigned)(paSI->outputLatency * paSI->sampleRate); 601 602 return PJ_SUCCESS; 603 } 604 547 605 548 606 /* -
pjproject/trunk/pjmedia/src/pjmedia/sound_port.c
r740 r744 125 125 if (snd_port->ec_suspended) { 126 126 snd_port->ec_suspended = PJ_FALSE; 127 //pjmedia_echo_state_reset(snd_port->ec_state); 127 128 PJ_LOG(4,(THIS_FILE, "EC activated")); 128 129 } … … 141 142 snd_port->ec_suspended = PJ_TRUE; 142 143 PJ_LOG(4,(THIS_FILE, "EC suspended because of inactivity")); 144 } 145 if (snd_port->ec_state) { 146 /* To maintain correct delay in EC */ 147 pjmedia_echo_playback(snd_port->ec_state, output); 143 148 } 144 149 } … … 354 359 355 360 /* 356 * Create sound recorder port.361 * Create sound recorder AEC. 357 362 */ 358 363 PJ_DEF(pj_status_t) pjmedia_snd_port_create_rec( pj_pool_t *pool, … … 457 462 unsigned options) 458 463 { 464 pjmedia_snd_stream_info si; 459 465 pj_status_t status; 460 466 … … 464 470 PJ_EINVALIDOP); 465 471 472 /* Sound port must have 16bits per sample */ 473 PJ_ASSERT_RETURN(snd_port->bits_per_sample == 16, 474 PJ_EINVALIDOP); 475 466 476 /* Destroy AEC */ 467 477 if (snd_port->ec_state) { … … 473 483 474 484 if (tail_ms != 0) { 485 unsigned delay_ms; 486 487 status = pjmedia_snd_stream_get_info(snd_port->snd_stream, &si); 488 if (status != PJ_SUCCESS) 489 si.rec_latency = si.play_latency = 0; 490 491 delay_ms = (si.rec_latency + si.play_latency) * 1000 / 492 snd_port->clock_rate; 475 493 status = pjmedia_echo_create(pool, snd_port->clock_rate, 476 494 snd_port->samples_per_frame,
Note: See TracChangeset
for help on using the changeset viewer.