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
45 static int sCaptureRef;
52 EAudioSessionType mAudioSession;
53 MMSessionType mMultimediaSession;
55 mm_sound_focus_type_e mFocusType; /* For audio focus */
56 mm_sound_focus_state_e mState; /* For audio focus */
57 char* mReasonForChange; /* For audio focus */
58 char* mAdditionalInfo; /* For audio focus */
60 CAudioInfo mAudioInfo; /* Referenced from CAudioIO */
62 IAudioSessionEventListener* mpEventListener;
69 struct stream_type_table_s {
73 const struct stream_type_table_s 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 stream_type_table_s 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 PCM_CAPTURE_COUNT_INC();
102 static int PCM_CAPTURE_COUNT_DEC();
103 static int PCM_CAPTURE_COUNT_GET();
104 static int FOCUS_ID_COUNT_INC();
105 static int FOCUS_ID_COUNT_DEC();
106 static int FOCUS_ID_COUNT_GET();
108 static void _sound_pcm_signal_cb(mm_sound_signal_name_t signal, int value, void *user_data);
109 static ASM_cb_result_t _sound_pcm_asm_cb(int handle, ASM_event_sources_t eventSrc, ASM_sound_commands_t command, unsigned int soundState, void *cbData);
110 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);
111 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);
114 CAudioError _convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
115 CAudioError _getAsmInformation(MMSessionType *type, int *options);
116 bool _isFocusRequired(MMSessionType type, int options);
119 /* Constructor & Destructor */
120 CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
121 virtual ~CAudioSessionHandler();
124 virtual void initialize() throw (CAudioError);
125 virtual void finalize();
127 bool isSkipSessionEvent() throw (CAudioError);
129 void registerSound() throw (CAudioError);
130 void unregisterSound() throw (CAudioError);
132 void updatePlaying() throw (CAudioError);
133 void updateStop() throw (CAudioError);
134 void disableSessionHandler() throw (CAudioError);
136 /* Setter & Getter */
140 EAudioSessionType getAudioSession();
141 MMSessionType getMultimediaSession();
143 int getSubscribeId();
145 CAudioInfo getAudioInfo();
149 } /* namespace tizen_media_audio */
152 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */