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_CAUDIO_IO_H__
18 #define __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__
24 namespace tizen_media_audio {
29 * You can't take this object directly.
31 class IPulseStreamListener;
32 class IAudioSessionEventListener;
33 class CAudioIO : public IPulseStreamListener, public IAudioSessionEventListener {
35 struct SStreamCallback {
37 void (*onStream)(size_t nbytes, void* user_data);
39 SStreamCallback() : mUserData(NULL), onStream(NULL)
43 struct SStateChangedCallback {
45 void (*onStateChanged)(CAudioInfo::EAudioIOState state, CAudioInfo::EAudioIOState statePrev, bool byPolicy, void* user_data);
47 SStateChangedCallback() : mUserData(NULL), onStateChanged(NULL)
51 struct SInterruptCallback {
53 void (*onInterrupt)(IAudioSessionEventListener::EInterruptCode code, void* user_data);
55 SInterruptCallback() : mUserData(NULL), onInterrupt(NULL)
60 pthread_mutex_t mMutex;
66 CAudioSessionHandler* mpAudioSessionHandler;
67 CPulseAudioClient* mpPulseAudioClient;
68 CAudioInfo mAudioInfo;
70 SStreamCallback mStreamCallback;
71 SStateChangedCallback mStateChangedCallback;
72 SInterruptCallback mInterruptCallback;
74 CAudioInfo::EAudioIOState mState;
75 CAudioInfo::EAudioIOState mStatePrev;
78 /* Protected Methods */
79 virtual void setInit(bool flag);
80 virtual bool isInit();
81 virtual bool IsReady();
83 void internalLock() throw (CAudioError);
84 void internalUnlock() throw (CAudioError);
85 void internalWait() throw (CAudioError);
86 void internalSignal() throw (CAudioError);
91 /* Constructor & Destructor */
93 CAudioIO(CAudioInfo& audioInfo);
96 /* Pure Virtual Methods */
97 virtual void initialize() throw (CAudioError) = 0;
98 virtual void finalize() = 0;
100 virtual void prepare() throw (CAudioError) = 0;
101 virtual void unprepare() throw (CAudioError) = 0;
103 virtual void pause() throw (CAudioError) = 0;
104 virtual void resume() throw (CAudioError) = 0;
106 virtual void drain() throw (CAudioError) = 0;
107 virtual void flush() throw (CAudioError) = 0;
109 virtual int getBufferSize() throw (CAudioError) = 0;
111 /* Implemented Handlers */
112 virtual void onStream(CPulseAudioClient* pClient, size_t length);
113 virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy);
114 virtual void onStateChanged(CAudioInfo::EAudioIOState state);
115 virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info);
116 virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value);
119 CAudioInfo getAudioInfo() throw (CAudioError);
121 virtual void setStreamCallback(SStreamCallback callback) throw (CAudioError);
122 SStreamCallback getStreamCallback() throw (CAudioError);
124 virtual void setStateChangedCallback(SStateChangedCallback callback) throw (CAudioError);
125 SStateChangedCallback getStateChangedCallback() throw (CAudioError);
127 void setInterruptCallback(SInterruptCallback callback) throw (CAudioError);
128 SInterruptCallback getInterruptCallback() throw (CAudioError);
130 void ignoreSession() throw (CAudioError);
133 } /* namespace tizen_media_audio */
136 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ */