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";
36 static const char* STREAM_NAME_OUTPUT_DEFAULT_ASYNC = "DEFAULT PLAYBACK ASYNC";
38 static const char* STREAM_LATENCY_LOW = "low";
39 static const char* STREAM_LATENCY_MID = "mid";
40 static const char* STREAM_LATENCY_HIGH = "high";
41 static const char* STREAM_LATENCY_VOIP = "voip";
42 static const char* STREAM_LATENCY_DEFAULT = "default";
43 static const char* STREAM_LATENCY_DEFAULT_ASYNC = "default-async";
45 CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo) :
47 __mAudioInfo(audioInfo) {
51 void CPulseStreamSpec::__adjustSpec() noexcept {
53 __mSampleSpec.rate = __mAudioInfo.getSampleRate();
55 // Convert channels for PA
56 __mSampleSpec.channels = static_cast<uint8_t>(__mAudioInfo.getChannel());
58 // Convert format for PA
59 switch (__mAudioInfo.getSampleType()) {
60 case CAudioInfo::ESampleType::SAMPLE_TYPE_U8:
61 __mSampleSpec.format = PA_SAMPLE_U8;
64 case CAudioInfo::ESampleType::SAMPLE_TYPE_S16_LE:
65 __mSampleSpec.format = PA_SAMPLE_S16LE;
68 case CAudioInfo::ESampleType::SAMPLE_TYPE_S24_LE:
69 __mSampleSpec.format = PA_SAMPLE_S24LE;
72 case CAudioInfo::ESampleType::SAMPLE_TYPE_S24_32_LE:
73 __mSampleSpec.format = PA_SAMPLE_S24_32LE;
76 case CAudioInfo::ESampleType::SAMPLE_TYPE_S32_LE:
77 __mSampleSpec.format = PA_SAMPLE_S32LE;
81 __mSampleSpec.format = PA_SAMPLE_S16LE;
86 pa_channel_map_init_extend(&__mChannelMap, __mSampleSpec.channels, PA_CHANNEL_MAP_ALSA);
91 case EStreamLatency::STREAM_LATENCY_INPUT_LOW:
92 __mStreamName = STREAM_NAME_INPUT_LOW_LATENCY;
95 case EStreamLatency::STREAM_LATENCY_INPUT_MID:
96 __mStreamName = STREAM_NAME_INPUT_MID_LATENCY;
99 case EStreamLatency::STREAM_LATENCY_INPUT_HIGH:
100 __mStreamName = STREAM_NAME_INPUT_HIGH_LATENCY;
103 case EStreamLatency::STREAM_LATENCY_INPUT_VOIP:
104 __mStreamName = STREAM_NAME_INPUT_VOIP;
108 case EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT:
109 __mStreamName = STREAM_NAME_INPUT_DEFAULT;
113 case EStreamLatency::STREAM_LATENCY_OUTPUT_LOW:
114 __mStreamName = STREAM_NAME_OUTPUT_LOW_LATENCY;
117 case EStreamLatency::STREAM_LATENCY_OUTPUT_MID:
118 __mStreamName = STREAM_NAME_OUTPUT_MID_LATENCY;
121 case EStreamLatency::STREAM_LATENCY_OUTPUT_HIGH:
122 __mStreamName = STREAM_NAME_OUTPUT_HIGH_LATENCY;
125 case EStreamLatency::STREAM_LATENCY_OUTPUT_VOIP:
126 __mStreamName = STREAM_NAME_OUTPUT_VOIP;
130 case EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT:
131 __mStreamName = STREAM_NAME_OUTPUT_DEFAULT;
134 case EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC:
135 __mStreamName = STREAM_NAME_OUTPUT_DEFAULT_ASYNC;
140 AUDIO_IO_LOGW("Invalid __mLatency[%d]", static_cast<int>(__mLatency));
146 CPulseStreamSpec::EStreamLatency CPulseStreamSpec::getStreamLatency() const noexcept {
150 const char* CPulseStreamSpec::getStreamLatencyToString() const noexcept {
153 switch (__mLatency) {
155 case EStreamLatency::STREAM_LATENCY_INPUT_LOW:
156 case EStreamLatency::STREAM_LATENCY_OUTPUT_LOW:
157 latency = STREAM_LATENCY_LOW;
160 case EStreamLatency::STREAM_LATENCY_INPUT_MID:
161 case EStreamLatency::STREAM_LATENCY_OUTPUT_MID:
162 latency = STREAM_LATENCY_MID;
165 case EStreamLatency::STREAM_LATENCY_INPUT_HIGH:
166 case EStreamLatency::STREAM_LATENCY_OUTPUT_HIGH:
167 latency = STREAM_LATENCY_HIGH;
170 case EStreamLatency::STREAM_LATENCY_INPUT_VOIP:
171 case EStreamLatency::STREAM_LATENCY_OUTPUT_VOIP:
172 latency = STREAM_LATENCY_VOIP;
176 case EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT:
177 case EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT:
178 latency = STREAM_LATENCY_DEFAULT;
181 case EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC:
182 latency = STREAM_LATENCY_DEFAULT_ASYNC;
187 AUDIO_IO_LOGW("Invalid __mLatency[%d]", static_cast<int>(__mLatency));
188 latency = STREAM_LATENCY_DEFAULT;
196 CAudioInfo& CPulseStreamSpec::getAudioInfo() noexcept {
200 pa_sample_spec CPulseStreamSpec::getSampleSpec() const noexcept {
201 return __mSampleSpec;
204 pa_channel_map CPulseStreamSpec::getChannelMap() const noexcept {
205 return __mChannelMap;
208 const char* CPulseStreamSpec::getStreamName() const noexcept {
209 return __mStreamName;