409e31112ddbc667ef3a2a2f40498489a1f0d204
[platform/core/api/audio-io.git] / include / CAudioSessionHandler.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__
18 #define __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__
19
20
21 #ifdef __cplusplus
22
23
24 #include <mm_session.h>
25 #include <mm_session_private.h>
26 #include <audio-session-manager.h>
27 #include <mm_sound.h>
28 #include <mm_sound_focus.h>
29
30 namespace tizen_media_audio {
31
32
33     /**
34      * ASM Thread
35      */
36     class CAudioSessionHandler {
37     public:
38         enum EAudioSessionType {
39             AUDIO_SESSION_TYPE_CAPTURE,
40             AUDIO_SESSION_TYPE_PLAYBACK
41         };
42
43         /* Constructor & Destructor */
44         CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
45         virtual ~CAudioSessionHandler();
46
47         /* Methods */
48         virtual void initialize() throw (CAudioError);
49         virtual void finalize();
50
51         bool isSkipSessionEvent() throw (CAudioError);
52
53         void registerSound() throw (CAudioError);
54         void unregisterSound() throw (CAudioError);
55
56         void updatePlaying() throw (CAudioError);
57         void updateStop() throw (CAudioError);
58         void disableSessionHandler() throw (CAudioError);
59
60         /* Setter & Getter */
61         int getId();
62         int getOptions();
63         EAudioSessionType  getAudioSession();
64         MMSessionType      getMultimediaSession();
65         int getSubscribeId();
66         CAudioInfo getAudioInfo();
67
68     private:
69         struct __streamTypeTable {
70             const char* name;
71             MMSessionType type;
72         };
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}
85         };
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}
98         };
99
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();
107
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);
111
112         /* Private Method */
113         CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
114         CAudioError __getAsmInformation(MMSessionType *type, int *options);
115         bool __isFocusRequired(MMSessionType type, int options);
116
117         /* Static Member */
118         static int                  __sCaptureRef;
119         static int                  __sFocusRef;
120
121         /* Members */
122         int                         __mId;
123         int                         __mOptions;
124
125         EAudioSessionType           __mAudioSession;
126         MMSessionType               __mMultimediaSession;
127
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 */
132
133         CAudioInfo                  __mAudioInfo;        /* Referenced from CAudioIO */
134
135         IAudioSessionEventListener* __mpEventListener;
136
137         bool                        __mIsInit;
138
139         bool                        __mUseFocus;
140         int                         __mSubscribeId;
141     };
142
143
144 } /* namespace tizen_media_audio */
145
146 #endif
147 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */