audio-io applied coding rule (JIRA : TSAM-430, TSAM-434)
[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
29 namespace tizen_media_audio {
30
31
32     /**
33      * ASM Thread
34      */
35     class CAudioSessionHandler {
36     public:
37         enum class EAudioSessionType : unsigned int {
38             AUDIO_SESSION_TYPE_CAPTURE,
39             AUDIO_SESSION_TYPE_PLAYBACK
40         };
41
42         /* Constructor & Destructor */
43         CAudioSessionHandler(EAudioSessionType sessionType, CAudioInfo& audioInfo, IAudioSessionEventListener* listener);
44         virtual ~CAudioSessionHandler();
45
46         /* Methods */
47         virtual void initialize() throw (CAudioError);
48         virtual void finalize();
49
50         bool isSkipSessionEvent() throw (CAudioError);
51
52         void registerSound() throw (CAudioError);
53         void unregisterSound() throw (CAudioError);
54
55         void updatePlaying() throw (CAudioError);
56         void updateStop() throw (CAudioError);
57         void disableSessionHandler() throw (CAudioError);
58
59         /* Setter & Getter */
60         int getId();
61         int getOptions();
62         EAudioSessionType  getAudioSession();
63         MMSessionType      getMultimediaSession();
64         int getSubscribeId();
65         CAudioInfo getAudioInfo();
66
67     private:
68         struct __streamTypeTable {
69             const char* name;
70             MMSessionType type;
71         };
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}
84         };
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}
97         };
98
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();
106
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, 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);
110
111         /* Private Method */
112         CAudioError __convertStreamType(EAudioSessionType type1, MMSessionType type2, int *index);
113         CAudioError __getAsmInformation(MMSessionType *type, int *options);
114         bool __isFocusRequired(MMSessionType type, int options);
115
116         /* Static Member */
117         static int                  __sCaptureRef;
118         static int                  __sFocusRef;
119
120         /* Members */
121         int                         __mId;
122         int                         __mOptions;
123
124         EAudioSessionType           __mAudioSession;
125         MMSessionType               __mMultimediaSession;
126
127         mm_sound_focus_type_e       __mFocusType;        /* For audio focus */
128         mm_sound_focus_state_e      __mState;            /* For audio focus */
129         char*                       __mReasonForChange;  /* For audio focus */
130         char*                       __mAdditionalInfo;   /* For audio focus */
131
132         CAudioInfo                  __mAudioInfo;        /* Referenced from CAudioIO */
133
134         IAudioSessionEventListener* __mpEventListener;
135
136         bool                        __mIsInit;
137
138         bool                        __mUseFocus;
139         int                         __mSubscribeId;
140     };
141
142
143 } /* namespace tizen_media_audio */
144
145 #endif
146 #endif /* __TIZEN_MEDIA_AUDIOIO_IO_CAUDIO_SESSION_HANDLER_H__ */