Changeset 4480 for pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c
- Timestamp:
- Apr 19, 2013 8:57:44 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c
r4475 r4480 53 53 #define THIS_FILE "bb10_dev.c" 54 54 #define BB10_DEVICE_NAME "plughw:%d,%d" 55 /* Double these for 16khz sampling */ 56 #define PREFERRED_FRAME_SIZE 320 57 #define VOIP_SAMPLE_RATE 8000 55 58 56 59 57 /* Set to 1 to enable tracing */ … … 434 432 { 435 433 struct bb10_stream* stream = (struct bb10_stream *) arg; 436 /* Handle from bb10_open_playback */437 /* Will be 640 */438 434 int size = stream->pb_buf_size; 439 /* 160 frames for 20ms */440 435 unsigned long nframes = stream->pb_frames; 441 436 void *user_data = stream->user_data; … … 683 678 } 684 679 680 static int32_t get_alsa_pcm_fmt(const pjmedia_aud_param *param) 681 { 682 switch (param->bits_per_sample) { 683 case 8: 684 return SND_PCM_SFMT_S8; 685 case 16: 686 return SND_PCM_SFMT_S16_LE; 687 case 24: 688 return SND_PCM_SFMT_S24_LE; 689 case 32: 690 return SND_PCM_SFMT_S32_LE; 691 default: 692 PJ_ASSERT_RETURN(!"Unsupported bits_per_frame", SND_PCM_SFMT_S16_LE); 693 } 694 } 695 685 696 static pj_status_t bb10_open_playback (struct bb10_stream *stream, 686 697 const pjmedia_aud_param *param) … … 697 708 return PJMEDIA_EAUD_INVDEV; 698 709 } 710 711 PJ_ASSERT_RETURN(param->bits_per_sample == 16, PJMEDIA_EAUD_SAMPFORMAT); 699 712 700 713 /* Use the bb10 audio manager API to open as opposed to QNX core audio … … 727 740 } 728 741 729 /* TODO PJ_ZERO */730 742 memset (&pi, 0, sizeof (pi)); 731 743 pi.channel = SND_PCM_CHANNEL_PLAYBACK; … … 742 754 pp.start_mode = SND_PCM_START_DATA; 743 755 pp.stop_mode = SND_PCM_STOP_ROLLOVER; 744 /* HARD CODE for the time being PJMEDIA expects 640 for 16khz */ 745 pp.buf.block.frag_size = PREFERRED_FRAME_SIZE*2; 756 pp.buf.block.frag_size = param->samples_per_frame * param->bits_per_sample / 8; 746 757 /* RIM recommends maximum of 3 */ 747 758 pp.buf.block.frags_max = 3; 748 759 pp.buf.block.frags_min = 1; 749 760 pp.format.interleave = 1; 750 /* HARD CODE for the time being PJMEDIA expects 16khz */ 751 PJ_TODO(REMOVE_SAMPLE_RATE_HARD_CODE); 752 pj_assert(param->clock_rate == VOIP_SAMPLE_RATE * 2); 753 pp.format.rate = VOIP_SAMPLE_RATE*2; 754 pp.format.voices = 1; 755 pp.format.format = SND_PCM_SFMT_S16_LE; 761 pp.format.rate = param->clock_rate; 762 pp.format.voices = param->channel_count; 763 pp.format.format = get_alsa_pcm_fmt(param); 756 764 757 765 /* Make the calls as per the wave sample */ … … 778 786 /* Set the sound device buffer size and latency */ 779 787 if (param->flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY) { 780 tmp_buf_size = (rate / 1000) * param->output_latency_ms;788 tmp_buf_size = rate * param->output_latency_ms / 1000; 781 789 } else { 782 tmp_buf_size = (rate / 1000) * PJMEDIA_SND_DEFAULT_PLAY_LATENCY;790 tmp_buf_size = rate * PJMEDIA_SND_DEFAULT_PLAY_LATENCY / 1000; 783 791 } 784 792 /* Set period size to samples_per_frame frames. */ 785 stream->pb_frames = param->samples_per_frame ;786 stream->param.output_latency_ms = tmp_buf_size / (rate / 1000);793 stream->pb_frames = param->samples_per_frame / param->channel_count; 794 stream->param.output_latency_ms = tmp_buf_size * 1000 / rate; 787 795 788 796 /* Set our buffer */ 789 797 stream->pb_buf_size = stream->pb_frames * param->channel_count * 790 (param->bits_per_sample/8);798 param->bits_per_sample / 8; 791 799 stream->pb_buf = (char *) pj_pool_alloc(stream->pool, stream->pb_buf_size); 792 800 … … 811 819 if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt) 812 820 return PJMEDIA_EAUD_INVDEV; 821 822 PJ_ASSERT_RETURN(param->bits_per_sample == 16, PJMEDIA_EAUD_SAMPFORMAT); 813 823 814 824 if ((ret=audio_manager_snd_pcm_open_name(AUDIO_TYPE_VIDEO_CHAT, … … 854 864 /* Auto-recover from errors */ 855 865 pp.stop_mode = SND_PCM_STOP_ROLLOVER; 856 /* HARD CODE for the time being PJMEDIA expects 640 for 16khz */ 857 pp.buf.block.frag_size = PREFERRED_FRAME_SIZE*2; 866 pp.buf.block.frag_size = param->samples_per_frame * param->bits_per_sample / 8; 858 867 /* From January 2013 gold OS release. RIM recommend these for capture */ 859 868 pp.buf.block.frags_max = 1; 860 869 pp.buf.block.frags_min = 1; 861 870 pp.format.interleave = 1; 862 /* HARD CODE for the time being PJMEDIA expects 16khz */ 863 PJ_TODO(REMOVE_SAMPLE_RATE_HARD_CODE); 864 pj_assert(param->clock_rate == VOIP_SAMPLE_RATE * 2); 865 pp.format.rate = VOIP_SAMPLE_RATE*2; 866 pp.format.voices = 1; 867 pp.format.format = SND_PCM_SFMT_S16_LE; 871 pp.format.rate = param->clock_rate; 872 pp.format.voices = param->channel_count; 873 pp.format.format = get_alsa_pcm_fmt(param); 868 874 869 875 /* make the request */ … … 898 904 /* Set the sound device buffer size and latency */ 899 905 if (param->flags & PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY) { 900 tmp_buf_size = (rate / 1000) * param->input_latency_ms;906 tmp_buf_size = rate * param->input_latency_ms / 1000; 901 907 } else { 902 tmp_buf_size = (rate / 1000) * PJMEDIA_SND_DEFAULT_REC_LATENCY;903 } 904 905 stream->param.input_latency_ms = tmp_buf_size / (rate / 1000);908 tmp_buf_size = rate * PJMEDIA_SND_DEFAULT_REC_LATENCY / 1000; 909 } 910 911 stream->param.input_latency_ms = tmp_buf_size * 1000 / rate; 906 912 907 913 /* Set our buffer */ 908 914 stream->ca_buf_size = stream->ca_frames * param->channel_count * 909 (param->bits_per_sample/8);915 param->bits_per_sample / 8; 910 916 stream->ca_buf = (char *)pj_pool_alloc (stream->pool, stream->ca_buf_size); 911 917 … … 966 972 } 967 973 968 /* Part of the play functionality but the RIM/Truphone loopback sample 969 * initialializes after the play and capture 970 * "false" is default/earpiece for output 971 */ 972 status = bb10_initialize_playback_ctrl(stream,false); 973 if (status != PJ_SUCCESS) { 974 return PJMEDIA_EAUD_SYSERR; 974 /* Set the audio routing ONLY if app explicitly asks one */ 975 if ((param->dir & PJMEDIA_DIR_PLAYBACK) && 976 (param->flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE)) 977 { 978 status = bb10_stream_set_cap(&stream->base, 979 PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE, 980 ¶m->output_route); 981 if (status != PJ_SUCCESS) { 982 TRACE_((THIS_FILE, "Error setting output route")); 983 bb10_stream_destroy(&stream->base); 984 return status; 985 } 986 } else { 987 /* Legacy behavior: if none specified, set to speaker */ 988 status = bb10_initialize_playback_ctrl(stream, false); 975 989 } 976 990
Note: See TracChangeset
for help on using the changeset viewer.