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>
27 #include <mm_sound_focus.h>
29 namespace tizen_media_audio {
35 class CAudioSessionHandler {
37 enum class EAudioSessionType : unsigned int {
38 AUDIO_SESSION_TYPE_CAPTURE,
39 AUDIO_SESSION_TYPE_PLAYBACK
42 /* Constructor & Destructor */
43 CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
44 virtual ~CAudioSessionHandler();
47 virtual void initialize() throw(CAudioError);
48 virtual void finalize();
50 bool isSkipSessionEvent() throw(CAudioError);
52 void registerSound() throw(CAudioError);
53 void unregisterSound() throw(CAudioError);
55 void updatePlaying() throw(CAudioError);
56 void updateStop() throw(CAudioError);
57 void disableSessionHandler() throw(CAudioError);
62 EAudioSessionType getAudioSession();
63 MMSessionType getMultimediaSession();
65 CAudioInfo getAudioInfo();
68 struct __streamTypeTable {
72 const struct __streamTypeTable __STREAM_TYPE_TABLE_IN[MM_SESSION_TYPE_NUM] = {
73 {"media", MM_SESSION_TYPE_MEDIA},
74 {"media", MM_SESSION_TYPE_MEDIA_RECORD},
75 {"media", MM_SESSION_TYPE_ALARM},
76 {"media", MM_SESSION_TYPE_NOTIFY},
77 {"media", MM_SESSION_TYPE_EMERGENCY},
78 {"media", MM_SESSION_TYPE_CALL},
79 {"media", MM_SESSION_TYPE_VIDEOCALL},
80 {"voip", MM_SESSION_TYPE_VOIP},
81 {"media", MM_SESSION_TYPE_VOICE_RECOGNITION},
82 {"media", MM_SESSION_TYPE_RECORD_AUDIO},
83 {"media", MM_SESSION_TYPE_RECORD_VIDEO}
85 const struct __streamTypeTable __STREAM_TYPE_TABLE_OUT[MM_SESSION_TYPE_NUM] = {
86 {"media", MM_SESSION_TYPE_MEDIA},
87 {"media", MM_SESSION_TYPE_MEDIA_RECORD},
88 {"alarm", MM_SESSION_TYPE_ALARM},
89 {"notification", MM_SESSION_TYPE_NOTIFY},
90 {"emergency", MM_SESSION_TYPE_EMERGENCY},
91 {"media", MM_SESSION_TYPE_CALL},
92 {"media", MM_SESSION_TYPE_VIDEOCALL},
93 {"voip", MM_SESSION_TYPE_VOIP},
94 {"media", MM_SESSION_TYPE_VOICE_RECOGNITION},
95 {"media", MM_SESSION_TYPE_RECORD_AUDIO},
96 {"media", MM_SESSION_TYPE_RECORD_VIDEO}
99 /* Private Static Methods */
100 static int __pcmCaptureCountInc();
101 static int __pcmCaptureCountDec();
102 static int __pcmCaptureCountGet();
103 static int __focusIdCountInc();
104 static int __focusIdCountDec();
105 static int __focusIdCountGet();
107 static void __sound_pcm_signal_cb(mm_sound_signal_name_t signal, int value, void *user_data);
108 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, int option, const char *additional_info, void *user_data);
109 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);
112 CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
113 CAudioError __getAsmInformation(MMSessionType *type, int *options);
114 bool __isFocusRequired(MMSessionType type, int options);
117 static int __sCaptureRef;
118 static int __sFocusRef;
124 EAudioSessionType __mAudioSession;
125 MMSessionType __mMultimediaSession;
127 CAudioInfo __mAudioInfo; /* Referenced from CAudioIO */
129 IAudioSessionEventListener* __mpEventListener;
135 mm_sound_focus_type_e __mFocusType; /* For audio focus */
136 mm_sound_focus_state_e __mState; /* For audio focus */
137 char* __mReasonForChange; /* For audio focus */
138 char* __mAdditionalInfo; /* For audio focus */
142 } /* namespace tizen_media_audio */
145 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */