- Timestamp:
- Feb 22, 2009 9:33:20 PM (16 years ago)
- Location:
- pjproject/branches/projects/aps-direct/pjmedia
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/config.h
r2468 r2471 292 292 */ 293 293 #ifndef PJMEDIA_FILE_PORT_BUFSIZE 294 # define PJMEDIA_FILE_PORT_BUFSIZE 294 # define PJMEDIA_FILE_PORT_BUFSIZE 4000 295 295 #endif 296 296 -
pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h
r2460 r2471 186 186 187 187 /** 188 * Format identifier definition.188 * This enumeration describes format ID. 189 189 */ 190 190 typedef enum pjmedia_format_id 191 191 { 192 /** 193 * 16bit linear 194 */ 192 195 PJMEDIA_FORMAT_L16 = 0, 196 197 /** 198 * Alias for PJMEDIA_FORMAT_L16 199 */ 200 PJMEDIA_FORMAT_PCM = PJMEDIA_FORMAT_L16, 201 202 /** 203 * G.711 ALAW 204 */ 193 205 PJMEDIA_FORMAT_PCMA = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'), 206 207 /** 208 * Alias for PJMEDIA_FORMAT_PCMA 209 */ 210 PJMEDIA_FORMAT_ALAW = PJMEDIA_FORMAT_PCMA, 211 212 /** 213 * G.711 ULAW 214 */ 194 215 PJMEDIA_FORMAT_PCMU = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'), 216 217 /** 218 * Aliaw for PJMEDIA_FORMAT_PCMU 219 */ 220 PJMEDIA_FORMAT_ULAW = PJMEDIA_FORMAT_PCMU, 221 222 /** 223 * AMR narrowband 224 */ 195 225 PJMEDIA_FORMAT_AMR = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'), 226 227 /** 228 * ITU G.729 229 */ 196 230 PJMEDIA_FORMAT_G729 = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'), 231 232 /** 233 * Internet Low Bit-Rate Codec (ILBC) 234 */ 197 235 PJMEDIA_FORMAT_ILBC = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C') 236 198 237 } pjmedia_format_id; 199 238 -
pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/wmme_dev.c
r2470 r2471 45 45 46 46 #define THIS_FILE "wmme_dev.c" 47 #define BITS_PER_SAMPLE 1648 #define BYTES_PER_SAMPLE (BITS_PER_SAMPLE/8)49 47 50 48 … … 103 101 104 102 void *buffer; /**< Temp. frame buffer. */ 103 pjmedia_format_id fmt_id; /**< Frame format */ 104 pj_uint8_t silence_char; /**< Silence pattern */ 105 105 unsigned clock_rate; /**< Clock rate. */ 106 106 unsigned bytes_per_frame; /**< Bytes per frame */ … … 456 456 pj_bzero(wfx, sizeof(PCMWAVEFORMAT)); 457 457 if (prm->ext_fmt.id == PJMEDIA_FORMAT_L16) { 458 enum { BYTES_PER_SAMPLE = 2 }; 458 459 wfx->wFormatTag = WAVE_FORMAT_PCM; 459 460 wfx->nChannels = (pj_uint16_t)prm->channel_count; … … 463 464 wfx->nAvgBytesPerSec = prm->clock_rate * prm->channel_count * 464 465 BYTES_PER_SAMPLE; 465 wfx->wBitsPerSample = BITS_PER_SAMPLE;466 wfx->wBitsPerSample = 16; 466 467 467 468 return PJ_SUCCESS; … … 495 496 } 496 497 498 /* Get format name */ 499 static const char *get_fmt_name(pj_uint32_t id) 500 { 501 static char name[8]; 502 503 if (id == PJMEDIA_FORMAT_L16) 504 return "l16"; 505 pj_memcpy(name, &id, 4); 506 name[4] = '\0'; 507 return name; 508 } 497 509 498 510 /* Internal: create WMME player device. */ … … 527 539 ptime = prm->samples_per_frame * 1000 / 528 540 (prm->clock_rate * prm->channel_count); 529 ptime = prm->samples_per_frame * 1000 / 530 (prm->clock_rate * prm->channel_count); 531 parent->bytes_per_frame = wfx.nAvgBytesPerSec / ptime; 541 parent->bytes_per_frame = wfx.nAvgBytesPerSec * ptime / 1000; 532 542 533 543 /* … … 575 585 /* Done setting up play device. */ 576 586 PJ_LOG(5, (THIS_FILE, 577 " WaveAPI Sound player \"%s\" initialized (clock_rate=%d, " 587 " WaveAPI Sound player \"%s\" initialized (" 588 "format=%s, clock_rate=%d, " 578 589 "channel_count=%d, samples_per_frame=%d (%dms))", 579 590 wf->dev_info[prm->play_id].info.name, 591 get_fmt_name(prm->ext_fmt.id), 580 592 prm->clock_rate, prm->channel_count, prm->samples_per_frame, 581 593 prm->samples_per_frame * 1000 / prm->clock_rate)); … … 613 625 ptime = prm->samples_per_frame * 1000 / 614 626 (prm->clock_rate * prm->channel_count); 615 parent->bytes_per_frame = wfx.nAvgBytesPerSec / ptime;627 parent->bytes_per_frame = wfx.nAvgBytesPerSec * ptime / 1000; 616 628 617 629 /* … … 653 665 /* Done setting up play device. */ 654 666 PJ_LOG(5,(THIS_FILE, 655 " WaveAPI Sound recorder \"%s\" initialized (clock_rate=%d, " 667 " WaveAPI Sound recorder \"%s\" initialized " 668 "(format=%s, clock_rate=%d, " 656 669 "channel_count=%d, samples_per_frame=%d (%dms))", 657 670 wf->dev_info[prm->rec_id].info.name, 671 get_fmt_name(prm->ext_fmt.id), 658 672 prm->clock_rate, prm->channel_count, prm->samples_per_frame, 659 673 prm->samples_per_frame * 1000 / prm->clock_rate)); … … 670 684 unsigned eventCount; 671 685 pj_status_t status = PJ_SUCCESS; 686 static unsigned rec_cnt, play_cnt; 687 688 rec_cnt = play_cnt = 0; 672 689 673 690 eventCount = 0; … … 701 718 pjmedia_dir signalled_dir; 702 719 720 /* Swap */ 721 if (eventCount==3) { 722 HANDLE hTemp = events[2]; 723 events[2] = events[1]; 724 events[1] = hTemp; 725 } 726 703 727 rc = WaitForMultipleObjects(eventCount, events, FALSE, INFINITE); 704 728 if (rc < WAIT_OBJECT_0 || rc >= WAIT_OBJECT_0 + eventCount) … … 739 763 void *buffer = wmme_strm->WaveHdr[wmme_strm->dwBufIdx].lpData; 740 764 pjmedia_frame pcm_frame, *frame; 741 pj_bool_t has_frame = PJ_FALSE;765 MMRESULT mr = MMSYSERR_NOERROR; 742 766 743 767 //PJ_LOG(5,(THIS_FILE, "Finished writing buffer %d", 744 768 // wmme_strm->dwBufIdx)); 745 769 746 if (strm-> xfrm == NULL) {770 if (strm->fmt_id == PJMEDIA_FORMAT_L16) { 747 771 /* PCM mode */ 748 772 frame = &pcm_frame; … … 765 789 766 790 /* Get frame from application. */ 791 PJ_LOG(5,(THIS_FILE, "xxx %u play_cb", play_cnt++)); 767 792 status = (*strm->play_cb)(strm->user_data, frame); 768 793 … … 770 795 break; 771 796 772 if (strm-> xfrm == NULL) {797 if (strm->fmt_id == PJMEDIA_FORMAT_L16) { 773 798 /* PCM mode */ 774 799 if (frame->type == PJMEDIA_FRAME_TYPE_NONE) { 775 800 pj_bzero(buffer, strm->bytes_per_frame); 776 has_frame = PJ_TRUE;777 801 } else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) { 778 802 pj_assert(!"Frame type not supported"); 779 803 } else if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) { 780 has_frame = PJ_TRUE;804 /* Nothing to do */ 781 805 } else { 782 806 pj_assert(!"Frame type not supported"); … … 785 809 /* Codec mode */ 786 810 if (frame->type == PJMEDIA_FRAME_TYPE_NONE) { 787 /* Not supported */ 811 pj_memset(buffer, strm->silence_char, 812 strm->bytes_per_frame); 788 813 } else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) { 789 814 unsigned sz; … … 791 816 buffer, 792 817 strm->bytes_per_frame); 793 pj_assert(sz == strm->bytes_per_frame); 818 if (sz < strm->bytes_per_frame) { 819 pj_memset((char*)buffer+sz, 820 strm->silence_char, 821 strm->bytes_per_frame - sz); 822 } 794 823 } else { 795 824 pj_assert(!"Frame type not supported"); … … 798 827 799 828 /* Write to the device. */ 800 if (has_frame) { 801 MMRESULT mr = MMSYSERR_NOERROR; 802 803 mr = waveOutWrite(wmme_strm->hWave.Out, 804 &(wmme_strm->WaveHdr[wmme_strm->dwBufIdx]), 805 sizeof(WAVEHDR)); 806 if (mr != MMSYSERR_NOERROR) { 807 status = CONVERT_MM_ERROR(mr); 808 break; 809 } 829 mr = waveOutWrite(wmme_strm->hWave.Out, 830 &(wmme_strm->WaveHdr[wmme_strm->dwBufIdx]), 831 sizeof(WAVEHDR)); 832 if (mr != MMSYSERR_NOERROR) { 833 status = CONVERT_MM_ERROR(mr); 834 break; 810 835 } 811 836 … … 864 889 */ 865 890 866 if (strm-> xfrm == NULL) {891 if (strm->fmt_id == PJMEDIA_FORMAT_L16) { 867 892 /* PCM mode */ 868 893 if (cap_len < strm->bytes_per_frame) … … 909 934 910 935 /* Call callback */ 936 PJ_LOG(5,(THIS_FILE, "xxx %u rec_cb", rec_cnt++)); 911 937 status = (*strm->rec_cb)(strm->user_data, frame); 912 938 if (status != PJ_SUCCESS) … … 938 964 pj_pool_t *pool; 939 965 struct wmme_stream *strm; 966 pj_uint8_t silence_char; 940 967 pj_status_t status; 941 968 942 /* Can only support 16bits per sample */ 943 PJ_ASSERT_RETURN(param->bits_per_sample == BITS_PER_SAMPLE, PJ_EINVAL); 969 switch (param->ext_fmt.id) { 970 case PJMEDIA_FORMAT_L16: 971 silence_char = '\0'; 972 break; 973 case PJMEDIA_FORMAT_ALAW: 974 silence_char = (pj_uint8_t)'\xd5'; 975 break; 976 case PJMEDIA_FORMAT_ULAW: 977 silence_char = (pj_uint8_t)'\xff'; 978 break; 979 default: 980 return PJMEDIA_EAUD_BADFORMAT; 981 } 944 982 945 983 /* Create and Initialize stream descriptor */ … … 955 993 strm->play_cb = play_cb; 956 994 strm->user_data = user_data; 995 strm->fmt_id = param->ext_fmt.id; 996 strm->silence_char = silence_char; 957 997 strm->clock_rate = param->clock_rate; 958 998 strm->samples_per_frame = param->samples_per_frame; 959 999 strm->bits_per_sample = param->bits_per_sample; 960 1000 strm->channel_count = param->channel_count; 961 strm->buffer = pj_pool_alloc(pool,962 param->samples_per_frame * BYTES_PER_SAMPLE);963 if (!strm->buffer) {964 pj_pool_release(pool);965 return PJ_ENOMEM;966 }967 1001 968 1002 /* Create player stream */ … … 1014 1048 } 1015 1049 1050 strm->buffer = pj_pool_alloc(pool, strm->bytes_per_frame); 1051 if (!strm->buffer) { 1052 pj_pool_release(pool); 1053 return PJ_ENOMEM; 1054 } 1055 1016 1056 /* If format is extended, must create buffer for the extended frame. */ 1017 if (param->ext_fmt.id != PJMEDIA_FORMAT_L16) { 1018 unsigned ptime = param->samples_per_frame * 1000 / 1019 (param->clock_rate * param->channel_count); 1057 if (strm->fmt_id != PJMEDIA_FORMAT_L16) { 1020 1058 strm->xfrm_size = sizeof(pjmedia_frame_ext) + 1021 1059 32 * sizeof(pjmedia_frame_ext_subframe) + 1022 (8000 * ptime / 1000)+ 4;1060 strm->bytes_per_frame + 4; 1023 1061 strm->xfrm = (pjmedia_frame_ext*) 1024 1062 pj_pool_alloc(pool, strm->xfrm_size); -
pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c
r2468 r2471 1293 1293 1294 1294 /* Return sound playback frame. */ 1295 do{1295 { 1296 1296 struct conf_port *this_cport = conf->ports[this_port->port_data.ldata]; 1297 1297 pjmedia_frame *f_src = (pjmedia_frame*) this_cport->tx_buf; … … 1355 1355 f_src_->subframe_cnt = 0; 1356 1356 } 1357 } while (0);1357 } 1358 1358 1359 1359 /* Unlock mutex */
Note: See TracChangeset
for help on using the changeset viewer.