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)
59 /* Constructor & Destructor */
61 CAudioIO(CAudioInfo& audioInfo);
64 /* Pure Virtual Methods */
65 virtual void initialize() throw(CAudioError) = 0;
66 virtual void finalize() = 0;
68 virtual void prepare() throw(CAudioError) = 0;
69 virtual void unprepare() throw(CAudioError) = 0;
71 virtual void pause() throw(CAudioError) = 0;
72 virtual void resume() throw(CAudioError) = 0;
74 virtual void drain() throw(CAudioError) = 0;
75 virtual void flush() throw(CAudioError) = 0;
77 virtual int getBufferSize() throw(CAudioError) = 0;
79 /* Implemented Handlers */
80 virtual void onStream(CPulseAudioClient* pClient, size_t length);
81 virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy);
82 virtual void onStateChanged(CAudioInfo::EAudioIOState state);
83 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);
84 virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value);
87 CAudioInfo& getAudioInfo() throw(CAudioError);
89 virtual void setStreamCallback(SStreamCallback callback) throw(CAudioError);
90 SStreamCallback getStreamCallback() throw(CAudioError);
92 virtual void setStateChangedCallback(SStateChangedCallback callback) throw(CAudioError);
93 SStateChangedCallback getStateChangedCallback() throw(CAudioError);
95 void setInterruptCallback(SInterruptCallback callback) throw(CAudioError);
96 SInterruptCallback getInterruptCallback() throw(CAudioError);
98 void ignoreSession() throw(CAudioError);
100 CAudioInfo::EAudioIOState getState();
103 /* Protected Methods */
104 virtual void setInit(bool flag);
105 virtual bool isInit();
106 virtual bool IsReady();
108 void internalLock() throw(CAudioError);
109 void internalUnlock() throw(CAudioError);
110 void internalWait() throw(CAudioError);
111 void internalSignal() throw(CAudioError);
113 bool isForceIgnore();
115 CAudioSessionHandler* mpAudioSessionHandler;
116 CPulseAudioClient* mpPulseAudioClient;
117 CAudioInfo mAudioInfo;
119 SStreamCallback mStreamCallback;
120 SStateChangedCallback mStateChangedCallback;
121 SInterruptCallback mInterruptCallback;
123 CAudioInfo::EAudioIOState mState;
124 CAudioInfo::EAudioIOState mStatePrev;
128 pthread_mutex_t __mMutex;
129 pthread_cond_t __mCond;
135 } /* namespace tizen_media_audio */
138 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ */