audio-io fixed build issue on 64-bit platform
[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     private:
60         pthread_mutex_t       mMutex;
61         pthread_cond_t        mCond;
62         bool                  mIsInit;
63         bool                  mForceIgnore;
64
65     protected:
66         CAudioSessionHandler* mpAudioSessionHandler;
67         CPulseAudioClient*    mpPulseAudioClient;
68         CAudioInfo            mAudioInfo;
69
70         SStreamCallback       mStreamCallback;
71         SStateChangedCallback mStateChangedCallback;
72         SInterruptCallback    mInterruptCallback;
73
74         CAudioInfo::EAudioIOState mState;
75         CAudioInfo::EAudioIOState mStatePrev;
76         bool                  mByPolicy;
77
78         /* Protected Methods */
79         virtual void setInit(bool flag);
80         virtual bool isInit();
81         virtual bool IsReady();
82
83         void internalLock()   throw (CAudioError);
84         void internalUnlock() throw (CAudioError);
85         void internalWait()   throw (CAudioError);
86         void internalSignal() throw (CAudioError);
87
88         bool isForceIgnore();
89
90     public:
91         /* Constructor & Destructor */
92         CAudioIO();
93         CAudioIO(CAudioInfo& audioInfo);
94         virtual ~CAudioIO();
95
96         /* Pure Virtual Methods */
97         virtual void initialize() throw (CAudioError) = 0;
98         virtual void finalize() = 0;
99
100         virtual void prepare() throw (CAudioError)   = 0;
101         virtual void unprepare() throw (CAudioError) = 0;
102
103         virtual void pause() throw (CAudioError) = 0;
104         virtual void resume() throw (CAudioError) = 0;
105
106         virtual void drain() throw (CAudioError) = 0;
107         virtual void flush() throw (CAudioError) = 0;
108
109         virtual int  getBufferSize() throw (CAudioError) = 0;
110
111         /* Implemented Handlers */
112         virtual void onStream(CPulseAudioClient* pClient, size_t length);
113         virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy);
114         virtual void onStateChanged(CAudioInfo::EAudioIOState state);
115         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);
116         virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value);
117
118         /* Methods */
119         CAudioInfo getAudioInfo() throw (CAudioError);
120
121         virtual void setStreamCallback(SStreamCallback callback) throw (CAudioError);
122         SStreamCallback getStreamCallback() throw (CAudioError);
123
124         virtual void setStateChangedCallback(SStateChangedCallback callback) throw (CAudioError);
125         SStateChangedCallback getStateChangedCallback() throw (CAudioError);
126
127         void setInterruptCallback(SInterruptCallback callback) throw (CAudioError);
128         SInterruptCallback getInterruptCallback() throw (CAudioError);
129
130         void ignoreSession() throw (CAudioError);
131     };
132
133 } /* namespace tizen_media_audio */
134
135 #endif
136 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ */