audio-io handles not supported stream type
[platform/core/api/audio-io.git] / src / cpp / CAudioInfo.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 <stdio.h>
19 #include "CAudioIODef.h"
20
21
22 using namespace std;
23 using namespace tizen_media_audio;
24
25
26 /**
27  * class CAudioInfo
28  */
29 CAudioInfo::CAudioInfo()
30     :  mSampleRate(MAX_SYSTEM_SAMPLERATE), mChannel(CHANNEL_MONO),
31        mSampleType(SAMPLE_TYPE_U8), mAudioType(AUDIO_IN_TYPE_MEDIA),
32        mAudioIndex(-1) {
33 }
34
35 CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) throw (CAudioError)
36     :  mSampleRate(sampleRate), mChannel(channel), mSampleType(sampleType), mAudioType(audioType), mAudioIndex(audioIndex) {
37     // Check to invalid AudioInfo
38     if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE || sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE) {
39         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The sampleRate is invalid [sampleRate:%d]", sampleRate);
40     }
41
42     if (channel < CAudioInfo::CHANNEL_MONO || channel >= CAudioInfo::CHANNEL_MAX) {
43         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The channel is invalid [channel:%d]", channel);
44     }
45
46     if (sampleType < CAudioInfo::SAMPLE_TYPE_U8 || sampleType >= CAudioInfo::SAMPLE_TYPE_MAX) {
47         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The sampleType is invalid [sampleType:%d]", sampleType);
48     }
49
50     if (audioType < CAudioInfo::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::AUDIO_TYPE_MAX) {
51         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The audioType is invalid [audioType:%d]", audioType);
52     }
53 }
54
55 unsigned int CAudioInfo::getSampleRate() {
56     return mSampleRate;
57 }
58
59 CAudioInfo::EChannel CAudioInfo::getChannel() {
60     return mChannel;
61 }
62
63 CAudioInfo::ESampleType CAudioInfo::getSampleType() {
64     return mSampleType;
65 }
66
67 CAudioInfo::EAudioType CAudioInfo::getAudioType() {
68     return mAudioType;
69 }
70
71 void CAudioInfo::setAudioType(CAudioInfo::EAudioType AudioType) {
72     mAudioType = AudioType;
73     return;
74 }
75
76 int CAudioInfo::getAudioIndex() {
77     return mAudioIndex;
78 }
79
80 void CAudioInfo::setAudioIndex(int AudioIndex) {
81     mAudioIndex = AudioIndex;
82     return;
83 }
84
85 void CAudioInfo::convertAudioType2StreamType (CAudioInfo::EAudioType audioType, char **streamType)
86 {
87     if (audioType < CAudioInfo::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::AUDIO_TYPE_MAX) {
88         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_NOT_SUPPORTED_TYPE, "The audioType is not supported [audioType:%d]", audioType);
89     }
90     *streamType = (char *)StreamTypeTable[audioType];
91     return;
92 }
93
94 void CAudioInfo::convertInputStreamType2AudioType (char *streamType, CAudioInfo::EAudioType *audioType)
95 {
96     unsigned int i;
97     for (i = CAudioInfo::AUDIO_IN_TYPE_MEDIA ; i < CAudioInfo::AUDIO_OUT_TYPE_MEDIA ; i++) {
98         if (!strcmp((char *)StreamTypeTable[i], streamType)) {
99             break;
100         }
101     }
102     if (i >= CAudioInfo::AUDIO_OUT_TYPE_MEDIA) {
103         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_NOT_SUPPORTED_TYPE, "The streamType is not supported [streamType:%s]", streamType);
104     }
105     *audioType = (CAudioInfo::EAudioType)i;
106     return;
107 }
108
109 void CAudioInfo::convertOutputStreamType2AudioType (char *streamType, CAudioInfo::EAudioType *audioType)
110 {
111     unsigned int i;
112     for (i = CAudioInfo::AUDIO_OUT_TYPE_MEDIA ; i < CAudioInfo::AUDIO_TYPE_MAX ; i++) {
113         if (!strcmp((char *)StreamTypeTable[i], streamType)) {
114             break;
115         }
116     }
117     if (i >= CAudioInfo::AUDIO_TYPE_MAX) {
118         THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_NOT_SUPPORTED_TYPE, "The streamType is not supported [streamType:%s]", streamType);
119     }
120     *audioType = (CAudioInfo::EAudioType)i;
121     return;
122 }
123