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>
28 #include <sound_manager.h>
29 #include <sound_manager_internal.h>
31 namespace tizen_media_audio {
37 class CAudioSessionHandler {
39 enum class EAudioSessionType : unsigned int {
40 AUDIO_SESSION_TYPE_CAPTURE,
41 AUDIO_SESSION_TYPE_PLAYBACK
44 /* Constructor & Destructor */
45 CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
46 virtual ~CAudioSessionHandler();
49 virtual void initialize() throw(CAudioError);
50 virtual void finalize();
52 bool isSkipSession() throw(CAudioError);
54 void registerSound() throw(CAudioError);
55 void unregisterSound() throw(CAudioError);
57 void updatePlaying() throw(CAudioError);
58 void updateStop() throw(CAudioError);
59 void disableSessionHandler() throw(CAudioError);
64 EAudioSessionType getAudioSession();
65 MMSessionType getMultimediaSession();
66 void getInternalVoipStreamInfo(sound_stream_info_h *stream_info);
67 unsigned int getSubscribeId();
68 CAudioInfo getAudioInfo();
71 struct __streamTypeTable {
75 const struct __streamTypeTable __STREAM_TYPE_TABLE_IN[MM_SESSION_TYPE_NUM] = {
76 {"media", MM_SESSION_TYPE_MEDIA},
77 {"media", MM_SESSION_TYPE_MEDIA_RECORD},
78 {"media", MM_SESSION_TYPE_ALARM},
79 {"media", MM_SESSION_TYPE_NOTIFY},
80 {"media", MM_SESSION_TYPE_EMERGENCY},
81 {"media", MM_SESSION_TYPE_CALL},
82 {"media", MM_SESSION_TYPE_VIDEOCALL},
83 {"voip", MM_SESSION_TYPE_VOIP},
84 {"media", MM_SESSION_TYPE_VOICE_RECOGNITION},
85 {"media", MM_SESSION_TYPE_RECORD_AUDIO},
86 {"media", MM_SESSION_TYPE_RECORD_VIDEO}
88 const struct __streamTypeTable __STREAM_TYPE_TABLE_OUT[MM_SESSION_TYPE_NUM] = {
89 {"media", MM_SESSION_TYPE_MEDIA},
90 {"media", MM_SESSION_TYPE_MEDIA_RECORD},
91 {"alarm", MM_SESSION_TYPE_ALARM},
92 {"notification", MM_SESSION_TYPE_NOTIFY},
93 {"emergency", MM_SESSION_TYPE_EMERGENCY},
94 {"media", MM_SESSION_TYPE_CALL},
95 {"media", MM_SESSION_TYPE_VIDEOCALL},
96 {"voip", MM_SESSION_TYPE_VOIP},
97 {"media", MM_SESSION_TYPE_VOICE_RECOGNITION},
98 {"media", MM_SESSION_TYPE_RECORD_AUDIO},
99 {"media", MM_SESSION_TYPE_RECORD_VIDEO}
102 /* Private Static Methods */
103 static int __pcmCaptureCountInc();
104 static int __pcmCaptureCountDec();
105 static int __pcmCaptureCountGet();
106 static int __focusIdCountInc();
107 static int __focusIdCountDec();
108 static int __focusIdCountGet();
110 static void __sound_pcm_signal_cb(mm_sound_signal_name_t signal, int value, void *user_data);
111 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);
112 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);
115 CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
116 CAudioError __getAsmInformation(MMSessionType *type, int *options);
117 bool __isFocusRequired(MMSessionType type, int options);
120 static int __sCaptureRef;
121 static int __sFocusRef;
127 EAudioSessionType __mAudioSession;
128 MMSessionType __mMultimediaSession;
130 CAudioInfo __mAudioInfo; /* Referenced from CAudioIO */
132 IAudioSessionEventListener* __mpEventListener;
135 unsigned int __mSubscribeId;
138 mm_sound_focus_type_e __mFocusType; /* For audio focus */
139 mm_sound_focus_state_e __mState; /* For audio focus */
140 char* __mReasonForChange; /* For audio focus */
141 char* __mAdditionalInfo; /* For audio focus */
145 } /* namespace tizen_media_audio */
148 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */