apply new version of audio-io for tizen 3.0
[platform/core/api/audio-io.git] / src / cpp / CPulseStreamSpec.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include "CAudioIODef.h"
19
20
21 using namespace std;
22 using namespace tizen_media_audio;
23
24
25 static const char* STREAM_NAME_INPUT               = "CAPTURE";
26 static const char* STREAM_NAME_INPUT_LOW_LATENCY   = "LOW 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
30 static const char* STREAM_NAME_OUTPUT              = "PLAYBACK";
31 static const char* STREAM_NAME_OUTPUT_LOW_LATENCY  = "LOW LATENCY PLAYBACK";
32 static const char* STREAM_NAME_OUTPUT_HIGH_LATENCY = "HIGH LATENCY PLAYBACK";
33 static const char* STREAM_NAME_OUTPUT_VOIP         = "VOIP PLAYBACK";
34
35
36 CPulseStreamSpec::CPulseStreamSpec() throw (CAudioError)
37         : mLatency(STREAM_LATENCY_INPUT_MID), mStreamName(NULL) {
38     _adjustSpec();
39 }
40
41 CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo) throw (CAudioError)
42         : mLatency(latency), mAudioInfo(audioInfo), mStreamName(NULL) {
43     _adjustSpec();
44 }
45
46 CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo, int customLatency) throw (CAudioError)
47         : mLatency(latency), mAudioInfo(audioInfo), mStreamName(NULL) {
48     _adjustSpec();
49 }
50
51 CPulseStreamSpec::~CPulseStreamSpec() {
52 }
53
54 void CPulseStreamSpec::_adjustSpec() throw (CAudioError) {
55     // Sets a sampleRate
56     mSampleSpec.rate = mAudioInfo.getSampleRate();
57
58     // Convert channels for PA
59     switch (mAudioInfo.getChannel()) {
60     case CAudioInfo::CHANNEL_MONO:
61         mSampleSpec.channels = 1;
62         break;
63
64     case CAudioInfo::CHANNEL_STEREO:
65     default:
66         mSampleSpec.channels = 2;
67         break;
68     }
69
70     // Convert format for PA
71     switch (mAudioInfo.getSampleType()) {
72     case CAudioInfo::SAMPLE_TYPE_U8:
73         mSampleSpec.format = PA_SAMPLE_U8;
74         break;
75
76     case CAudioInfo::SAMPLE_TYPE_S16_LE:
77     default:
78         mSampleSpec.format = PA_SAMPLE_S16LE;
79         break;
80     }
81
82     // Sets channelmap
83     pa_channel_map_init_auto(&mChannelMap, mSampleSpec.channels, PA_CHANNEL_MAP_ALSA);
84
85     // Sets stream name
86     switch (mLatency) {
87     case STREAM_LATENCY_OUTPUT_MID:
88         mStreamName = STREAM_NAME_OUTPUT;
89         break;
90
91     case STREAM_LATENCY_OUTPUT_HIGH:
92         mStreamName = STREAM_NAME_OUTPUT_HIGH_LATENCY;
93         break;
94
95     case STREAM_LATENCY_OUTPUT_LOW:
96         mStreamName = STREAM_NAME_OUTPUT_LOW_LATENCY;
97         break;
98
99     case STREAM_LATENCY_OUTPUT_VOIP:
100          mStreamName = STREAM_NAME_OUTPUT_VOIP;
101          break;
102
103     case STREAM_LATENCY_INPUT_HIGH:
104         mStreamName = STREAM_NAME_INPUT_HIGH_LATENCY;
105         break;
106
107     case STREAM_LATENCY_INPUT_LOW:
108         mStreamName = STREAM_NAME_INPUT_LOW_LATENCY;
109         break;
110
111     case STREAM_LATENCY_INPUT_VOIP:
112         mStreamName = STREAM_NAME_INPUT_VOIP;
113         break;
114
115     case STREAM_LATENCY_INPUT_MID:
116     default:
117         mStreamName = STREAM_NAME_INPUT;
118         break;
119     }
120 }
121
122 CPulseStreamSpec::EStreamLatency CPulseStreamSpec::getStreamLatency() {
123     return mLatency;
124 }
125
126 CAudioInfo CPulseStreamSpec::getAudioInfo() {
127     return mAudioInfo;
128 }
129
130 pa_sample_spec CPulseStreamSpec::getSampleSpec() {
131     return mSampleSpec;
132 }
133
134 pa_channel_map CPulseStreamSpec::getChannelMap() {
135     return mChannelMap;
136 }
137
138 const char* CPulseStreamSpec::getStreamName() {
139     return mStreamName;
140 }