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_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__
18 #define __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__
24 #include <mm_session.h>
25 #include <mm_session_private.h>
26 #include <audio-session-manager.h>
28 #include <mm_sound_focus.h>
30 namespace tizen_media_audio {
36 class CAudioSessionHandler {
38 enum EAudioSessionType {
39 AUDIO_SESSION_TYPE_CAPTURE,
40 AUDIO_SESSION_TYPE_PLAYBACK
43 /* Constructor & Destructor */
44 CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
45 virtual ~CAudioSessionHandler();
48 virtual void initialize() throw (CAudioError);
49 virtual void finalize();
51 bool isSkipSessionEvent() throw (CAudioError);
53 void registerSound() throw (CAudioError);
54 void unregisterSound() throw (CAudioError);
56 void updatePlaying() throw (CAudioError);
57 void updateStop() throw (CAudioError);
58 void disableSessionHandler() throw (CAudioError);
63 EAudioSessionType getAudioSession();
64 MMSessionType getMultimediaSession();
66 CAudioInfo getAudioInfo();
69 struct __streamTypeTable {
73 const struct __streamTypeTable __STREAM_TYPE_TABLE_IN[MM_SESSION_TYPE_NUM] = {
74 {"media", MM_SESSION_TYPE_MEDIA},
75 {"media", MM_SESSION_TYPE_MEDIA_RECORD},
76 {"media", MM_SESSION_TYPE_ALARM},
77 {"media", MM_SESSION_TYPE_NOTIFY},
78 {"media", MM_SESSION_TYPE_EMERGENCY},
79 {"media", MM_SESSION_TYPE_CALL},
80 {"media", MM_SESSION_TYPE_VIDEOCALL},
81 {"voip", MM_SESSION_TYPE_VOIP},
82 {"media", MM_SESSION_TYPE_VOICE_RECOGNITION},
83 {"media", MM_SESSION_TYPE_RECORD_AUDIO},
84 {"media", MM_SESSION_TYPE_RECORD_VIDEO}
86 const struct __streamTypeTable __STREAM_TYPE_TABLE_OUT[MM_SESSION_TYPE_NUM] = {
87 {"media", MM_SESSION_TYPE_MEDIA},
88 {"media", MM_SESSION_TYPE_MEDIA_RECORD},
89 {"alarm", MM_SESSION_TYPE_ALARM},
90 {"notification", MM_SESSION_TYPE_NOTIFY},
91 {"emergency", MM_SESSION_TYPE_EMERGENCY},
92 {"media", MM_SESSION_TYPE_CALL},
93 {"media", MM_SESSION_TYPE_VIDEOCALL},
94 {"voip", MM_SESSION_TYPE_VOIP},
95 {"media", MM_SESSION_TYPE_VOICE_RECOGNITION},
96 {"media", MM_SESSION_TYPE_RECORD_AUDIO},
97 {"media", MM_SESSION_TYPE_RECORD_VIDEO}
100 /* Private Static Methods */
101 static int __pcmCaptureCountInc();
102 static int __pcmCaptureCountDec();
103 static int __pcmCaptureCountGet();
104 static int __focusIdCountInc();
105 static int __focusIdCountDec();
106 static int __focusIdCountGet();
108 static void __sound_pcm_signal_cb(mm_sound_signal_name_t signal, int value, void *user_data);
109 static void __sound_pcm_focus_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
110 static void __sound_pcm_focus_watch_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
113 CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
114 CAudioError __getAsmInformation(MMSessionType *type, int *options);
115 bool __isFocusRequired(MMSessionType type, int options);
118 static int __sCaptureRef;
119 static int __sFocusRef;
125 EAudioSessionType __mAudioSession;
126 MMSessionType __mMultimediaSession;
128 mm_sound_focus_type_e __mFocusType; /* For audio focus */
129 mm_sound_focus_state_e __mState; /* For audio focus */
130 char* __mReasonForChange; /* For audio focus */
131 char* __mAdditionalInfo; /* For audio focus */
133 CAudioInfo __mAudioInfo; /* Referenced from CAudioIO */
135 IAudioSessionEventListener* __mpEventListener;
144 } /* namespace tizen_media_audio */
147 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */