audio-io fixed reference of CAudioInfo, check supported stream info
[platform/core/api/audio-io.git] / include / CAudioIO.h
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 #ifndef __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__
18 #define __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__
19
20
21 #ifdef __cplusplus
22
23
24 namespace tizen_media_audio {
25
26
27     /**
28      *  Abstract Class
29      *  You can't take this object directly.
30      */
31     class IPulseStreamListener;
32     class IAudioSessionEventListener;
33     class CAudioIO : public IPulseStreamListener, public IAudioSessionEventListener {
34     public:
35         struct SStreamCallback {
36             void* mUserData;
37             void (*onStream)(size_t nbytes, void* user_data);
38
39             SStreamCallback() : mUserData(NULL), onStream(NULL)
40             { /* Empty Body */ }
41         };
42
43         struct SStateChangedCallback {
44             void* mUserData;
45             void (*onStateChanged)(CAudioInfo::EAudioIOState state, CAudioInfo::EAudioIOState statePrev, bool byPolicy, void* user_data);
46
47             SStateChangedCallback() : mUserData(NULL), onStateChanged(NULL)
48             { /* Empty Body */ }
49         };
50
51         struct SInterruptCallback {
52             void* mUserData;
53             void (*onInterrupt)(IAudioSessionEventListener::EInterruptCode code, void* user_data);
54
55             SInterruptCallback() : mUserData(NULL), onInterrupt(NULL)
56             { /* Empty Body */ }
57         };
58
59         /* Constructor & Destructor */
60         CAudioIO();
61         CAudioIO(CAudioInfo& audioInfo);
62         virtual ~CAudioIO();
63
64         /* Pure Virtual Methods */
65         virtual void initialize() throw (CAudioError) = 0;
66         virtual void finalize() = 0;
67
68         virtual void prepare() throw (CAudioError)   = 0;
69         virtual void unprepare() throw (CAudioError) = 0;
70
71         virtual void pause() throw (CAudioError) = 0;
72         virtual void resume() throw (CAudioError) = 0;
73
74         virtual void drain() throw (CAudioError) = 0;
75         virtual void flush() throw (CAudioError) = 0;
76
77         virtual int  getBufferSize() throw (CAudioError) = 0;
78
79         /* Implemented Handlers */
80         virtual void onStream(CPulseAudioClient* pClient, size_t length);
81         virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy);
82         virtual void onStateChanged(CAudioInfo::EAudioIOState state);
83         virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info);
84         virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value);
85
86         /* Methods */
87         CAudioInfo& getAudioInfo() throw (CAudioError);
88
89         virtual void setStreamCallback(SStreamCallback callback) throw (CAudioError);
90         SStreamCallback getStreamCallback() throw (CAudioError);
91
92         virtual void setStateChangedCallback(SStateChangedCallback callback) throw (CAudioError);
93         SStateChangedCallback getStateChangedCallback() throw (CAudioError);
94
95         void setInterruptCallback(SInterruptCallback callback) throw (CAudioError);
96         SInterruptCallback getInterruptCallback() throw (CAudioError);
97
98         void ignoreSession() throw (CAudioError);
99
100     protected:
101         /* Protected Methods */
102         virtual void setInit(bool flag);
103         virtual bool isInit();
104         virtual bool IsReady();
105
106         void internalLock()   throw (CAudioError);
107         void internalUnlock() throw (CAudioError);
108         void internalWait()   throw (CAudioError);
109         void internalSignal() throw (CAudioError);
110
111         bool isForceIgnore();
112
113         CAudioSessionHandler* mpAudioSessionHandler;
114         CPulseAudioClient*    mpPulseAudioClient;
115         CAudioInfo            mAudioInfo;
116
117         SStreamCallback       mStreamCallback;
118         SStateChangedCallback mStateChangedCallback;
119         SInterruptCallback    mInterruptCallback;
120
121         CAudioInfo::EAudioIOState mState;
122         CAudioInfo::EAudioIOState mStatePrev;
123         bool                  mByPolicy;
124
125     private:
126         pthread_mutex_t       __mMutex;
127         pthread_cond_t        __mCond;
128         bool                  __mIsInit;
129         bool                  __mForceIgnore;
130     };
131
132
133 } /* namespace tizen_media_audio */
134
135 #endif
136 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ */