audio-io changed some focus & session APIs
[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 #include <pulse/ext-policy.h>
26
27
28 namespace tizen_media_audio {
29
30
31     /**
32      * PULSE Thread
33      */
34     class CPulseAudioVolume;
35     class CPulseAudioPolicy;
36     class CPulseStreamSpec;
37     class CPulseAudioClient {
38     public:
39         enum class EStreamDirection : unsigned int {
40             STREAM_DIRECTION_RECORD,        /**< Record stream */
41             STREAM_DIRECTION_PLAYBACK       /**< Playback stream */
42         };
43
44         /* Constants */
45         static const char* CLIENT_NAME;
46
47         /* Constructor & Destructor */
48         CPulseAudioClient(EStreamDirection      direction,
49                           CPulseStreamSpec&     spec,
50                           IPulseStreamListener* listener);
51         ~CPulseAudioClient();
52
53         /* Implemented Methods */
54         void initialize() throw (CAudioError);
55         void finalize();
56
57         /* Methods */
58         int  peek(const void** data, size_t* length) throw (CAudioError);
59         int  drop() throw (CAudioError);
60         int  write(const void* data, size_t length) throw (CAudioError);
61
62         void cork(bool cork) throw (CAudioError);
63         bool isCorked() throw (CAudioError);
64
65         bool drain() throw (CAudioError);
66         bool flush() throw (CAudioError);
67
68         void checkRunningState() throw (CAudioError);
69         bool isInThread() throw (CAudioError);
70
71         size_t getWritableSize() throw (CAudioError);
72         size_t getReadableSize() throw (CAudioError);
73
74         size_t getBufferSize() throw (CAudioError);
75
76         pa_usec_t getLatency() throw (CAudioError);
77         pa_usec_t getFinalLatency() throw (CAudioError);
78
79         /* Setter & Getter */
80         EStreamDirection getStreamDirection();
81         CPulseStreamSpec getStreamSpec();
82
83     private:
84         /* Members */
85         EStreamDirection      __mDirection;
86         CPulseStreamSpec      __mSpec;
87         IPulseStreamListener* __mpListener;
88
89         pa_threaded_mainloop* __mpMainloop;
90         pa_context*           __mpContext;
91         pa_stream*            __mpStream;
92         pa_proplist*          __mpPropList;
93
94         bool                  __mIsInit;
95         bool                  __mIsOperationSuccess;
96
97         /* Static Methods */
98
99         /* Private Method */
100
101         /* Private Calblack Method */
102         static void __contextStateChangeCb(pa_context* c, void* user_data);
103         static void __successContextCb(pa_context* c, int success, void* user_data);
104
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 __successStreamCb(pa_stream* s, int success, void* user_data);
110     };
111
112
113 } /* namespace tizen_media_audio */
114
115 #endif
116 #endif /* __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__ */