summaryrefslogtreecommitdiff
path: root/lib-common/inc/Common/SoundManager.h
blob: 86389850827080216bfea346d9e47c1f57e09322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright 2017 Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://floralicense.org/license/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef COMMON_SOUND_MANAGER_H
#define COMMON_SOUND_MANAGER_H

#include <functional>
#include <sound_manager.h>

#define SOUND_STREAM_FOCUS_CHANGED_BY_NONE -1

namespace Common
{
	/**
	 * @brief Create sound manager for sound interaction with other applications.
	 */
	class EXPORT_API SoundManager
	{
	public:
		/**
		 * @brief Media types.
		 */
		enum MediaType
		{
			MediaTypeRecorder,
			MediaTypePlayer
		};
		/**
		 * @brief Called when the focus changed.
		 * @param[in]   mask    The focus mask.
		 * @param[in]   state   The focus state.
		 * @param[in]   reason  The change reason.
		 * @see sound_stream_focus_mask_e
		 * @see sound_stream_focus_state_e
		 * @see sound_stream_focus_change_reason_e
		 */
		typedef std::function<void(sound_stream_focus_mask_e mask, sound_stream_focus_state_e state,
				sound_stream_focus_change_reason_e reason)> FocusChangeCallback;

		/**
		 * @brief Create sound manager.
		 * @param[in]   type   Stream type.
		 */
		explicit SoundManager(sound_stream_type_e type);
		~SoundManager();
		SoundManager(const SoundManager &) = delete;
		SoundManager &operator=(const SoundManager &) = delete;

		/**
		 * @brief Get stream information handle.
		 */
		sound_stream_info_h getStreamInfo() const;

		/**
		 * @brief Acquires the stream focus.
		 * @see releaseFocus()
		 */
		void acquireFocus();

		/**
		 * @brief Release the stream focus.
		 * @pre Call acquireFocus() before calling this function.
		 * @see acquireFocus()
		 */
		void releaseFocus();

		/**
		 * @brief Set focus change callback.
		 * @param[in]   callback   Recording callback.
		 */
		void setFocusChangeCallback(FocusChangeCallback callback);

		/**
		 * @brief Whether the sound is focused by a call.
		 * @param[in]   type   Media type.
		 * @return true if focused by call.
		 */
		static bool isSoundFocusedByCall(MediaType type);

		/**
		 * @brief Get the reason of sound focus change.
		 * @param[in]   type   Media type.
		 * @return sound_stream_focus_change_reason_e on success, SOUND_STREAM_FOCUS_CHANGED_BY_NONE - otherwise.
		 * @see sound_stream_focus_change_reason_e
		 */
		static int getSoundFocusChangedReason(MediaType type);

	private:
		void onFocusState(sound_stream_info_h streamInfo, sound_stream_focus_mask_e focusMask,
				sound_stream_focus_state_e focusState, sound_stream_focus_change_reason_e reason,
				int soundBehavior, const char *extraInfo);

		sound_stream_info_h m_StreamInfo;
		FocusChangeCallback m_OnFocusChanged;

		sound_stream_focus_mask_e m_FocusMask;
		sound_stream_focus_state_e m_FocusState;
		sound_stream_focus_change_reason_e m_ChangeReason;
	};
}

#endif /* COMMON_SOUND_MANAGER_H */