Remove 3.0 deprecated API implementation
[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 #include <sound_manager.h>
21
22 #ifdef __cplusplus
23
24
25 namespace tizen_media_audio {
26
27
28     /**
29      *  Abstract Class
30      *  You can't take this object directly.
31      */
32     class IPulseStreamListener;
33     class CAudioIO : public IPulseStreamListener {
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         /* Constructor & Destructor */
52         CAudioIO();
53         CAudioIO(CAudioInfo& audioInfo);
54         virtual ~CAudioIO();
55
56         /* Pure Virtual Methods */
57         virtual void initialize() = 0;
58         virtual void finalize() = 0;
59
60         virtual void prepare() = 0;
61         virtual void unprepare() = 0;
62
63         virtual void pause() = 0;
64         virtual void resume() = 0;
65
66         virtual void drain() = 0;
67         virtual void flush() = 0;
68
69         virtual int  getBufferSize() = 0;
70
71         /* Implemented Handlers */
72         virtual void onStream(CPulseAudioClient* pClient, size_t length);
73         virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy);
74         virtual void onStateChanged(CAudioInfo::EAudioIOState state);
75
76         /* Methods */
77         CAudioInfo& getAudioInfo();
78
79         virtual void setStreamCallback(SStreamCallback callback);
80         SStreamCallback getStreamCallback();
81
82         virtual void setStateChangedCallback(SStateChangedCallback callback);
83         SStateChangedCallback getStateChangedCallback();
84
85         void setStreamInfo(sound_stream_info_h stream_info);
86
87         CAudioInfo::EAudioIOState getState();
88
89     protected:
90         /* Protected Methods */
91         virtual void setInit(bool flag);
92         virtual bool isInit();
93         virtual bool IsReady();
94
95         void internalLock();
96         void internalUnlock();
97         void internalWait();
98         void internalSignal();
99
100         CPulseAudioClient*    mpPulseAudioClient;
101         CAudioInfo            mAudioInfo;
102
103         SStreamCallback       mStreamCallback;
104         SStateChangedCallback mStateChangedCallback;
105
106         CAudioInfo::EAudioDirection mDirection;
107         CAudioInfo::EAudioIOState mState;
108         CAudioInfo::EAudioIOState mStatePrev;
109         bool                  mByPolicy;
110
111     private:
112         pthread_mutex_t       __mMutex;
113         pthread_mutex_t       __mCondMutex;
114         pthread_cond_t        __mCond;
115         bool                  __mIsInit;
116     };
117
118
119 } /* namespace tizen_media_audio */
120
121 #endif
122 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ */