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 void setStreamInfo(sound_stream_info_h stream_info) throw(CAudioError);
102 void setInternalStreamInfo() throw(CAudioError); /* this is for session backward compatibility and will be removed later */
104 CAudioInfo::EAudioIOState getState();
107 /* Protected Methods */
108 virtual void setInit(bool flag);
109 virtual bool isInit();
110 virtual bool IsReady();
112 void internalLock() throw(CAudioError);
113 void internalUnlock() throw(CAudioError);
114 void internalWait() throw(CAudioError);
115 void internalSignal() throw(CAudioError);
117 bool isForceIgnore();
119 CAudioSessionHandler* mpAudioSessionHandler;
120 CPulseAudioClient* mpPulseAudioClient;
121 CAudioInfo mAudioInfo;
123 SStreamCallback mStreamCallback;
124 SStateChangedCallback mStateChangedCallback;
125 SInterruptCallback mInterruptCallback;
127 CAudioInfo::EAudioDirection mDirection;
128 CAudioInfo::EAudioIOState mState;
129 CAudioInfo::EAudioIOState mStatePrev;
133 pthread_mutex_t __mMutex;
134 pthread_cond_t __mCond;
138 void abandonInternalFocus() throw(CAudioError); /* this is for session backward compatibility and will be removed later */
142 } /* namespace tizen_media_audio */
145 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__ */