Revise cpp codes
[platform/core/api/audio-io.git] / include / CPulseAudioClient.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_CPULSEAUDIO_CLIENT_H__
18 #define __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__
19
20
21 #ifdef __cplusplus
22
23
24 #include <pulse/pulseaudio.h>
25
26
27 namespace tizen_media_audio {
28
29
30     /**
31      * PULSE Thread
32      */
33     class CPulseStreamSpec;
34     class CPulseAudioClient {
35     public:
36         enum class EStreamDirection : unsigned int {
37             STREAM_DIRECTION_RECORD,        /**< Record stream */
38             STREAM_DIRECTION_PLAYBACK       /**< Playback stream */
39         };
40
41         /* Constants */
42         static const char* CLIENT_NAME;
43
44         /* Constructor & Destructor */
45         CPulseAudioClient(EStreamDirection      direction,
46                           CPulseStreamSpec&     spec,
47                           IPulseStreamListener* listener);
48         ~CPulseAudioClient();
49
50         /* Implemented Methods */
51         void initialize();
52         void finalize();
53
54         /* Methods */
55         int read(void* buffer, size_t length);
56         int peek(const void** buffer, size_t* length);
57         int drop();
58         int write(const void* buffer, size_t length);
59
60         void cork(bool cork);
61         bool isCorked();
62
63         bool drain();
64         bool flush();
65
66         void checkRunningState();
67         bool isInThread() noexcept;
68
69         size_t getWritableSize();
70         size_t getReadableSize();
71
72         size_t getBufferSize();
73
74         pa_usec_t getLatency();
75         pa_usec_t getFinalLatency();
76
77     private:
78         /* Members */
79         EStreamDirection      __mDirection;
80         CPulseStreamSpec      __mSpec;
81         IPulseStreamListener* __mpListener;
82
83         pa_threaded_mainloop* __mpMainloop;
84         pa_context*           __mpContext;
85         pa_stream*            __mpStream;
86         pa_proplist*          __mpPropList;
87
88         bool                  __mIsInit;
89         bool                  __mIsOperationSuccess;
90
91         const void*           __mpSyncReadDataPtr;
92         size_t                __mSyncReadIndex;
93         size_t                __mSyncReadLength;
94         bool                  __mIsUsedSyncRead;
95         bool                  __mIsFirstStream;
96         bool                  __mIsDraining;
97         bool                  __mIsStarted;
98
99         /* Static Methods */
100
101         /* Private Method */
102
103         /* Private Calblack Method */
104         static void __contextStateChangeCb(pa_context* c, void* user_data);
105         static void __streamStateChangeCb(pa_stream* s, void* user_data);
106         static void __streamCaptureCb(pa_stream* s, size_t length, void* user_data);
107         static void __streamPlaybackCb(pa_stream* s, size_t length, void* user_data);
108         static void __streamLatencyUpdateCb(pa_stream* s, void* user_data);
109         static void __streamStartedCb(pa_stream* s, void* user_data);
110         static void __streamUnderflowCb(pa_stream* s, void* user_data);
111         static void __streamEventCb(pa_stream* s, const char *name, pa_proplist *pl, void *user_data);
112         static void __successStreamCb(pa_stream* s, int success, void* user_data);
113         static void __successDrainCb(pa_stream* s, int success, void* user_data);
114         static void __successDrainCbInThread(pa_stream* s, int success, void* user_data);
115     };
116
117
118 } /* namespace tizen_media_audio */
119
120 #endif
121 #endif /* __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__ */