2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "CAudioIODef.h"
22 using namespace tizen_media_audio;
25 static const char* STREAM_NAME_INPUT_LOW_LATENCY = "LOW LATENCY CAPTURE";
26 static const char* STREAM_NAME_INPUT_MID_LATENCY = "MID LATENCY CAPTURE";
27 static const char* STREAM_NAME_INPUT_HIGH_LATENCY = "HIGH LATENCY CAPTURE";
28 static const char* STREAM_NAME_INPUT_VOIP = "VOIP CAPTURE";
29 static const char* STREAM_NAME_INPUT_DEFAULT = "DEFAULT CAPTURE";
31 static const char* STREAM_NAME_OUTPUT_LOW_LATENCY = "LOW LATENCY PLAYBACK";
32 static const char* STREAM_NAME_OUTPUT_MID_LATENCY = "MID LATENCY PLAYBACK";
33 static const char* STREAM_NAME_OUTPUT_HIGH_LATENCY = "HIGH LATENCY PLAYBACK";
34 static const char* STREAM_NAME_OUTPUT_VOIP = "VOIP PLAYBACK";
35 static const char* STREAM_NAME_OUTPUT_DEFAULT = "DEFAULT PLAYBACK";
37 static const char* STREAM_LATENCY_LOW = "low";
38 static const char* STREAM_LATENCY_MID = "mid";
39 static const char* STREAM_LATENCY_HIGH = "high";
40 static const char* STREAM_LATENCY_VOIP = "voip";
41 static const char* STREAM_LATENCY_DEFAULT = "default";
44 CPulseStreamSpec::CPulseStreamSpec() throw(CAudioError) :
45 __mLatency(EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT),
50 CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo) throw(CAudioError) :
52 __mAudioInfo(audioInfo),
57 CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo, int customLatency) throw(CAudioError) :
59 __mAudioInfo(audioInfo),
64 CPulseStreamSpec::~CPulseStreamSpec() {
67 void CPulseStreamSpec::__adjustSpec() throw(CAudioError) {
69 __mSampleSpec.rate = __mAudioInfo.getSampleRate();
71 // Convert channels for PA
72 switch (__mAudioInfo.getChannel()) {
73 case CAudioInfo::EChannel::CHANNEL_MONO:
74 __mSampleSpec.channels = 1;
77 case CAudioInfo::EChannel::CHANNEL_STEREO:
79 __mSampleSpec.channels = 2;
83 // Convert format for PA
84 switch (__mAudioInfo.getSampleType()) {
85 case CAudioInfo::ESampleType::SAMPLE_TYPE_U8:
86 __mSampleSpec.format = PA_SAMPLE_U8;
89 case CAudioInfo::ESampleType::SAMPLE_TYPE_S16_LE:
91 __mSampleSpec.format = PA_SAMPLE_S16LE;
96 pa_channel_map_init_auto(&__mChannelMap, __mSampleSpec.channels, PA_CHANNEL_MAP_ALSA);
100 case EStreamLatency::STREAM_LATENCY_INPUT_LOW:
101 __mStreamName = STREAM_NAME_INPUT_LOW_LATENCY;
104 case EStreamLatency::STREAM_LATENCY_INPUT_MID:
105 __mStreamName = STREAM_NAME_INPUT_MID_LATENCY;
108 case EStreamLatency::STREAM_LATENCY_INPUT_HIGH:
109 __mStreamName = STREAM_NAME_INPUT_HIGH_LATENCY;
112 case EStreamLatency::STREAM_LATENCY_INPUT_VOIP:
113 __mStreamName = STREAM_NAME_INPUT_VOIP;
116 case EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT:
117 __mStreamName = STREAM_NAME_INPUT_DEFAULT;
120 case EStreamLatency::STREAM_LATENCY_OUTPUT_LOW:
121 __mStreamName = STREAM_NAME_OUTPUT_LOW_LATENCY;
124 case EStreamLatency::STREAM_LATENCY_OUTPUT_MID:
125 __mStreamName = STREAM_NAME_OUTPUT_MID_LATENCY;
128 case EStreamLatency::STREAM_LATENCY_OUTPUT_HIGH:
129 __mStreamName = STREAM_NAME_OUTPUT_HIGH_LATENCY;
132 case EStreamLatency::STREAM_LATENCY_OUTPUT_VOIP:
133 __mStreamName = STREAM_NAME_OUTPUT_VOIP;
136 case EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT:
137 __mStreamName = STREAM_NAME_OUTPUT_DEFAULT;
141 AUDIO_IO_LOGW("Invalid __mLatency[%d]", __mLatency);
146 CPulseStreamSpec::EStreamLatency CPulseStreamSpec::getStreamLatency() {
150 const char* CPulseStreamSpec::getStreamLatencyToString() {
153 switch (__mLatency) {
154 case EStreamLatency::STREAM_LATENCY_INPUT_LOW:
155 case EStreamLatency::STREAM_LATENCY_OUTPUT_LOW:
156 latency = STREAM_LATENCY_LOW;
159 case EStreamLatency::STREAM_LATENCY_INPUT_MID:
160 case EStreamLatency::STREAM_LATENCY_OUTPUT_MID:
161 latency = STREAM_LATENCY_MID;
164 case EStreamLatency::STREAM_LATENCY_INPUT_HIGH:
165 case EStreamLatency::STREAM_LATENCY_OUTPUT_HIGH:
166 latency = STREAM_LATENCY_HIGH;
169 case EStreamLatency::STREAM_LATENCY_INPUT_VOIP:
170 case EStreamLatency::STREAM_LATENCY_OUTPUT_VOIP:
171 latency = STREAM_LATENCY_VOIP;
174 case EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT:
175 case EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT:
176 latency = STREAM_LATENCY_DEFAULT;
180 AUDIO_IO_LOGW("Invalid __mLatency[%d]", __mLatency);
181 latency = STREAM_LATENCY_DEFAULT;
188 CAudioInfo& CPulseStreamSpec::getAudioInfo() {
192 pa_sample_spec CPulseStreamSpec::getSampleSpec() {
193 return __mSampleSpec;
196 pa_channel_map CPulseStreamSpec::getChannelMap() {
197 return __mChannelMap;
200 const char* CPulseStreamSpec::getStreamName() {
201 return __mStreamName;