Abandon internal focus if it exists when setStreamInfo() is called
[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 <mm_sound.h>
27 #include <mm_sound_focus.h>
28 #include <sound_manager.h>
29 #include <sound_manager_internal.h>
30
31 namespace tizen_media_audio {
32
33
34     /**
35      * ASM Thread
36      */
37     class CAudioSessionHandler {
38     public:
39         enum class EAudioSessionType : unsigned int {
40             AUDIO_SESSION_TYPE_CAPTURE,
41             AUDIO_SESSION_TYPE_PLAYBACK
42         };
43
44         /* Constructor & Destructor */
45         CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
46         virtual ~CAudioSessionHandler();
47
48         /* Methods */
49         virtual void initialize() throw(CAudioError);
50         virtual void finalize();
51
52         bool isSkipSession();
53
54         void registerSound() throw(CAudioError);
55         void unregisterSound() throw(CAudioError);
56
57         void updatePlaying() throw(CAudioError);
58         void updateStop() throw(CAudioError);
59         void disableSessionHandler() throw(CAudioError);
60
61         /* Setter & Getter */
62         int getId();
63         int getOptions();
64         EAudioSessionType  getAudioSession();
65         MMSessionType      getMultimediaSession();
66         void getInternalVoipStreamInfo(sound_stream_info_h *stream_info);
67         unsigned int getSubscribeId();
68         CAudioInfo getAudioInfo();
69
70     private:
71         struct __streamTypeTable {
72             const char* name;
73             MMSessionType type;
74         };
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}
87         };
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}
100         };
101
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();
109
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);
113
114         /* Private Method */
115         CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
116         CAudioError __getAsmInformation(MMSessionType *type, int *options);
117         bool __isFocusRequired(MMSessionType type, int options);
118
119         /* Static Member */
120         static int                  __sCaptureRef;
121         static int                  __sFocusRef;
122
123         /* Members */
124         int                         __mId;
125         int                         __mOptions;
126
127         EAudioSessionType           __mAudioSession;
128         MMSessionType               __mMultimediaSession;
129
130         CAudioInfo                  __mAudioInfo;        /* Referenced from CAudioIO */
131
132         IAudioSessionEventListener* __mpEventListener;
133
134         bool                        __mIsInit;
135         unsigned int                __mSubscribeId;
136
137         bool                        __mUseFocus;
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 */
142     };
143
144
145 } /* namespace tizen_media_audio */
146
147 #endif
148 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */