2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__
18 #define __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__
24 #include <pulse/pulseaudio.h>
25 #include <pulse/ext-policy.h>
28 namespace tizen_media_audio {
34 class CPulseAudioVolume;
35 class CPulseAudioPolicy;
36 class CPulseStreamSpec;
37 class CPulseAudioClient {
40 static const char* CLIENT_NAME;
42 enum EStreamDirection {
43 STREAM_DIRECTION_RECORD, /**< Record stream */
44 STREAM_DIRECTION_PLAYBACK /**< Playback stream */
49 EStreamDirection mDirection;
50 CPulseStreamSpec mSpec;
51 IPulseStreamListener* mpListener;
53 pa_threaded_mainloop* mpMainloop;
54 pa_context* mpContext;
56 pa_proplist* mpPropList;
59 bool mIsOperationSuccess;
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);
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);
76 /* Constructor & Destructor */
77 CPulseAudioClient(EStreamDirection direction,
78 CPulseStreamSpec& spec,
79 IPulseStreamListener* listener);
82 /* Implemented Methods */
83 void initialize() throw (CAudioError);
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);
91 void cork(bool cork) throw (CAudioError);
92 bool isCorked() throw (CAudioError);
94 bool drain() throw (CAudioError);
95 bool flush() throw (CAudioError);
97 void checkRunningState() throw (CAudioError);
98 bool isInThread() throw (CAudioError);
100 size_t getWritableSize() throw (CAudioError);
101 size_t getReadableSize() throw (CAudioError);
103 size_t getBufferSize() throw (CAudioError);
105 pa_usec_t getLatency() throw (CAudioError);
106 pa_usec_t getFinalLatency() throw (CAudioError);
108 /* Setter & Getter */
109 EStreamDirection getStreamDirection();
110 CPulseStreamSpec getStreamSpec();
114 } /* namespace tizen_media_audio */
117 #endif /* __TIZEN_MEDIA_AUDIO_IO_CPULSEAUDIO_CLIENT_H__ */