summaryrefslogtreecommitdiff
path: root/mm_sound.c
blob: 96b98a2a5bf734ed98150fc906aa7a6274f021ef (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
 * libmm-sound
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 *
 */

#include <stdlib.h>
#include <memory.h>
#include <unistd.h>
#include <pthread.h>

#include <errno.h>

#include <vconf.h>
#include <mm_types.h>
#include <mm_error.h>
#include <mm_debug.h>
#include "include/mm_sound_private.h"
#include "include/mm_sound_utils.h"
#include "include/mm_sound_client.h"
#include "include/mm_sound_pa_client.h"
#include "include/mm_sound_common.h"

#define MASTER_VOLUME_MAX 100
#define MASTER_VOLUME_MIN 0

#include <gio/gio.h>

#define MM_SOUND_DBUS_BUS_NAME_PREPIX  "org.tizen.MMSound"
#define MM_SOUND_DBUS_OBJECT_PATH  "/org/tizen/MMSound"
#define MM_SOUND_DBUS_INTERFACE    "org.tizen.mmsound"

static const char* _get_volume_str(volume_type_t type)
{
	static const char *volume_type_str[VOLUME_TYPE_MAX] = {
		"SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"
	};

	return (type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
}

static const char* _get_volume_str_internal(volume_type_internal_t type)
{
	static const char *volume_type_str[] = {
		"BIXBY"
	};

	return (type < (VOLUME_TYPE_BIXBY + 1)) ? volume_type_str[type] : "Unknown";
}

EXPORT_API
int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id)
{
	int ret = MM_ERROR_NONE;

	if (func == NULL || subs_id == NULL) {
		debug_error("argument is not valid");
		return MM_ERROR_INVALID_ARGUMENT;
	}

	ret = mm_sound_client_add_volume_changed_callback(func, user_data, subs_id);
	if (ret < 0) {
		debug_error("Can not add volume changed callback, ret = %x", ret);
	}

	return ret;
}

EXPORT_API
int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
{
	int ret = MM_ERROR_NONE;

	ret = mm_sound_client_remove_volume_changed_callback(subs_id);
	if (ret < 0) {
		debug_error("Can not remove volume changed callback, ret = %x", ret);
	}

	return ret;
}

EXPORT_API
int mm_sound_volume_set_value(volume_type_t type, const unsigned int value)
{
	int ret = MM_ERROR_NONE;

	/* request daemon to set volume */
	ret = mm_sound_client_set_volume_by_type(type, value);
	if (ret)
		debug_error("can not set volume, type(%s), value(%d), ret=0x%x", _get_volume_str(type), value, ret);
	else
		debug_msg("set (%s) volume to (%d)",  _get_volume_str(type), value);

	return ret;
}

EXPORT_API
int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
{
	int ret = MM_ERROR_NONE;

	ret = mm_sound_client_get_volume_by_type(type, value);
	if (ret)
		debug_error("can not get volume, type(%s), ret=0x%x", _get_volume_str(type), ret);
	else
		debug_msg("(%s) volume : %d",  _get_volume_str(type), *value);

	return ret;
}

EXPORT_API
int mm_sound_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* user_data, unsigned int *subs_id)
{
	int ret = MM_ERROR_NONE;

	if (func == NULL || subs_id == NULL) {
		debug_error("argument is not valid");
		return MM_ERROR_INVALID_ARGUMENT;
	}

	ret = mm_sound_client_add_volume_changed_callback_internal(func, user_data, subs_id);
	if (ret < 0)
		debug_error("Can not add internal volume changed callback, ret = %x", ret);

	return ret;
}

EXPORT_API
int mm_sound_remove_volume_changed_callback_internal(unsigned int subs_id)
{
	int ret = MM_ERROR_NONE;

	ret = mm_sound_client_remove_volume_changed_callback(subs_id);
	if (ret < 0)
		debug_error("Can not remove internal volume changed callback, ret = %x", ret);

	return ret;
}

EXPORT_API
int mm_sound_volume_set_value_internal(volume_type_internal_t type, const unsigned int value)
{
	int ret = MM_ERROR_NONE;

	/* request daemon to set volume */
	ret = mm_sound_client_set_volume_by_internal_type(type, value);
	if (ret)
		debug_error("can not set internal volume, type(%s), value(%d), ret=0x%x", _get_volume_str_internal(type), value, ret);
	else
		debug_msg("set (%s) volume to (%d)",  _get_volume_str_internal(type), value);

	return ret;
}

EXPORT_API
int mm_sound_volume_get_value_internal(volume_type_internal_t type, unsigned int *value)
{
	int ret = MM_ERROR_NONE;

	ret = mm_sound_client_get_volume_by_internal_type(type, value);
	if (ret)
		debug_error("can not get internal volume, type(%s), ret=0x%x", _get_volume_str_internal(type), ret);
	else
		debug_msg("(%s) volume : %d",  _get_volume_str_internal(type), *value);

	return ret;
}

EXPORT_API
int mm_sound_set_mute(volume_type_t type, bool mute)
{
	int ret = MM_ERROR_NONE;

	ret = mm_sound_client_set_mute_by_type(type, mute);
	if (ret)
		debug_error("can not set mute, type(%s), mute(%d), ret=0x%x", _get_volume_str(type), mute, ret);
	else
		debug_msg("set (%s) mute to (%d)",  _get_volume_str(type), mute);

	return ret;
}

EXPORT_API
int mm_sound_get_mute(volume_type_t type, bool  *muted)
{
	int ret = MM_ERROR_NONE;

	/* Check input param */
	if (!muted) {
		debug_error("invalid argument");
		return MM_ERROR_INVALID_ARGUMENT;
	}
	if (type > VOLUME_TYPE_VOICE) {
		debug_error("invalid volume type value %d", type);
		return MM_ERROR_INVALID_ARGUMENT;
	}

	ret = mm_sound_client_get_mute_by_type(type, muted);
	if (ret)
		debug_error("can not get mute, type(%s), ret=0x%x", _get_volume_str(type), ret);
	else
		debug_msg("(%s) mute state : %d",  _get_volume_str(type), *muted);

	return ret;
}

EXPORT_API
int mm_sound_set_filter(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
{
	/* Check input param */
	if (!stream_type || !filter_name) {
		debug_error("invalid argument");
		return MM_ERROR_INVALID_ARGUMENT;
	}
	if (!filter_parameters)
		filter_parameters = "";
	if (!filter_group)
		filter_group = "default";

	debug_msg("stream_type(%s), filter_name(%s), filter_parameters(%s), filter_group(%s)", stream_type, filter_name, filter_parameters, filter_group);

	return mm_sound_client_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
}

EXPORT_API
int mm_sound_unset_filter(const char *stream_type)
{
	/* Check input param */
	if (!stream_type) {
		debug_error("invalid argument");
		return MM_ERROR_INVALID_ARGUMENT;
	}

	debug_msg("stream_type(%s)", stream_type);

	return mm_sound_client_unset_filter_by_type(stream_type);
}

EXPORT_API
int mm_sound_control_filter(const char *stream_type, const char *filter_name, const char *filter_controls)
{
	/* Check input param */
	if (!stream_type || !filter_name || !filter_controls) {
		debug_error("invalid argument");
		return MM_ERROR_INVALID_ARGUMENT;
	}

	debug_msg("stream_type(%s), filter_name(%s), filter_controls(%s)", stream_type, filter_name, filter_controls);

	return mm_sound_client_control_filter_by_type(stream_type, filter_name, filter_controls);
}

///////////////////////////////////
////     MMSOUND ROUTING APIs
///////////////////////////////////

EXPORT_API
int mm_sound_add_ducking_state_changed_callback(mm_sound_ducking_state_changed_cb func, void *user_data, unsigned int *subs_id)
{
	int ret = MM_ERROR_NONE;

	if (func == NULL || subs_id == NULL) {
		debug_error("argument is not valid");
		return MM_ERROR_INVALID_ARGUMENT;
	}

	ret = mm_sound_client_add_ducking_state_changed_callback(func, user_data, subs_id);
	if (ret < 0) {
		debug_error("Can not add ducking state changed callback, ret = %x", ret);
	}

	return ret;
}

EXPORT_API
int mm_sound_remove_ducking_state_changed_callback(unsigned int subs_id)
{
	int ret = MM_ERROR_NONE;

	ret = mm_sound_client_remove_ducking_state_changed_callback(subs_id);
	if (ret < 0) {
		debug_error("Can not remove ducking state changed callback, ret = %x", ret);
	}

	return ret;
}

#ifdef TIZEN_TV
EXPORT_API
void mm_sound_dotnet_cleanup(int signo)
{
}
#endif

__attribute__ ((constructor))
static void _mm_sound_initialize(void)
{
	mm_sound_client_initialize();
	/* Will be Fixed */
}

__attribute__ ((destructor))
static void _mm_sound_finalize(void)
{
	mm_sound_client_finalize();
}