apply new version of audio-io for tizen 3.0
[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         /* Constants */
40         static const char* CLIENT_NAME;
41
42         enum EStreamDirection {
43             STREAM_DIRECTION_RECORD,        /**< Record stream */
44             STREAM_DIRECTION_PLAYBACK       /**< Playback stream */
45         };
46
47     private:
48         /* Members */
49         EStreamDirection      mDirection;
50         CPulseStreamSpec      mSpec;
51         IPulseStreamListener* mpListener;
52
53         pa_threaded_mainloop* mpMainloop;
54         pa_context*           mpContext;
55         pa_stream*            mpStream;
56         pa_proplist*          mpPropList;
57
58         bool                  mIsInit;
59         bool                  mIsOperationSuccess;
60
61         /* Static Methods */
62
63         /* Private Method */
64
65         /* Private Calblack Method */
66         static void _contextStateChangeCb(pa_context* c, void* user_data);
67         static void _successContextCb(pa_context* c, int success, void* user_data);
68
69         static void _streamStateChangeCb(pa_stream* s, void* user_data);
70         static void _streamCaptureCb(pa_stream* s, size_t length, void* user_data);
71         static void _streamPlaybackCb(pa_stream* s, size_t length, void* user_data);
72         static void _streamLatencyUpdateCb(pa_stream* s, void* user_data);
73         static void _successStreamCb(pa_stream* s, int success, void* user_data);
74
75     public:
76         /* Constructor & Destructor */
77         CPulseAudioClient(EStreamDirection      direction,
78                           CPulseStreamSpec&     spec,
79                           IPulseStreamListener* listener);
80         ~CPulseAudioClient();
81
82         /* Implemented Methods */
83         void initialize() throw (CAudioError);
84         void finalize();
85
86         /* Methods */
87         int  peek(const void** data, size_t* length) throw (CAudioError);
88         int  drop() throw (CAudioError);
89         int  write(const void* data, size_t length) throw (CAudioError);
90
91         void cork(bool cork) throw (CAudioError);
92         bool isCorked() throw (CAudioError);
93
94         bool drain() throw (CAudioError);
95         bool flush() throw (CAudioError);
96
97         void checkRunningState() throw (CAudioError);
98         bool isInThread() throw (CAudioError);
99
100         size_t getWritableSize() throw (CAudioError);
101         size_t getReadableSize() throw (CAudioError);
102
103         size_t getBufferSize() throw (CAudioError);
104
105         pa_usec_t getLatency() throw (CAudioError);
106         pa_usec_t getFinalLatency() throw (CAudioError);
107
108         /* Setter & Getter */
109         EStreamDirection getStreamDirection();
110         CPulseStreamSpec getStreamSpec();
111     };
112
113
114 } /* namespace tizen_media_audio */
115
116 #endif
117 #endif /* __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__ */