aboutsummaryrefslogtreecommitdiffstats
path: root/src/soundmanager.h
blob: c03f7184da0816c5d3f8742d57b0b08973945691 (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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/*
 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
 *
 * 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.
 */
#ifndef SOUNDMANAGER_H
#define SOUNDMANAGER_H

#define _GNU_SOURCE
#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include "dbus/audio_manager_interface.h"

/*
********** Method of Sound Manager (API) **********
*/

/**
 * Call "connect" function of Audio Manager.
 * Getting resource right to output audio stream.
 * Please input following keys with value into json string object in argument.
 * In case of using libsoundmanager,
 * json_object *jobj = json_object_new_object();
 * json_object_object_add(jobj, "sourceID", json_object_new_int(100));
 * json_object_object_add(jobj, "sinkID", json_object_new_int(100));
 * call("connect", jobj);
 *
 * The order of arguments is not important.
 *
 * #### Parameters
 * Request key
 * - sourceID   : Source ID getting in return value in registerSource or appname.
 * - sinkID     : Sink ID. This should be more than 0. If no request, defalut value is set by sound manager
 *
 * This will be changed in near future because these arguments should be aliased like
 * sinkID:100 -> sinkID:"speaker"
 *
 * This will be modified after integrating
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 * sourceID and sinkID should be more than 0
 *
 */
void connect (struct afb_req request);

/**
 * Call "disconnect" function of Audio Manager.
 * Release resource right to output audio stream.
 *
 * #### Parameters
 * Request key
 * - sourceID   : Source ID getting in return value in registerSource or appname.
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 * sourceID should be more than 0
 *
 */
void disconnect (struct afb_req request);

/**
 * Call "setVolume" function of Audio Manager.
 * Set sink volume.
 *
 * #### Parameters
 * Request key
 * - volume   : volume value. The range of value should be [0-100]
 * - sinkID   : sinkID you would like to change volume at
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void setVolume (struct afb_req request);

/**
 * Call "volumeStep" function of Audio Manager.
 * Change volume step of sink
 *
 * #### Parameters
 * Request key
 * - sinkID     : sinkID you would to change volume step
 * - volumeStep : Step size of volume
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void volumeStep (struct afb_req request);

/**
 * Call "volumeStep" function of Audio Manager.
 * Change volume step of sink
 *
 * #### Parameters
 * Request key
 * - sinkID     : sinkID you would like to change mute state
 * - muteState  : muteState, 1 means mute, 2 means unmute. Or you can designate as "mute" or "unmute"
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void setSinkMuteState(struct afb_req request);

/**
 * Call "getListMainConnections" function of Audio Manager.
 * Get mainc connection list
 *
 * #### Parameters
 * Request key
 * None
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
 *   Sound Manager return success.
 *
 * #### Note
 *
 */
void getListMainConnections(struct afb_req request);

/**
 * Call "getListMainSources" function of Audio Manager.
 * Get main source list
 *
 * #### Parameters
 * Request key
 * None
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
 *   Sound Manager return success.
 *
 * #### Note
 *
 */
void getListMainSources(struct afb_req request);

/**
 * Call "getListMainSinks" function of Audio Manager.
 * Get main sink list
 *
 * #### Parameters
 * Request key
 * None
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
 *   Sound Manager return success.
 *
 * #### Note
 *
 */
void getListMainSinks(struct afb_req request);

/**
 * Call "ackConnect" function of Audio Manager.
 * Return acknowledge of connect against asyncConnect
 *
 * #### Parameters
 *  - handle  : Handle id when you get on asyncConnect
 *  - connectionID : connection id when you got on connect return value
 *  - error   : Error Number you would like to send. If error is 0, it means OK.
 *              If an application has some error, send error number in function then AM release
 *              resources the application got in connect.
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
 *   Sound Manager return success. So you should check the contents size of return json object
 *
 * #### Note
 *
 */
void ackConnect(struct afb_req request);

/**
 * Call "ackDisconnect" function of Audio Manager.
 * Return acknowledge of disconnect against asyncDisconnect
 *
 * #### Parameters
 *  - handle  : Handle id when you get on asyncDisconnect
 *  - connectionID : connection id when you got on connect return value
 *  - error   : Error Number you would like to send. If error is 0, it means OK.
 *              If an application has some error, send error number in function then AM
 *
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
 *   Sound Manager return success. So you should check the contents size of return json object
 *
 * #### Note
 *
 */
void ackDisconnect(struct afb_req request);

/**
 * Call "ackSetSourceState" function of Audio Manager.
 * Return acknowledge of setSourceState against asyncSetSourceState.
 *
 * #### Parameters
 *  - handle  : Handle id when you get on asyncSetSourceState
 *  - error   : Error Number you would like to send. If error is 0, it means OK.
 *              If an application has some errors, send error number in function
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 * This function is very important for applications to realise the sequence of Audio Management.
 * An Application which matches with sourceID in the parameter of asyncSetSourceState has to return ack to use this function
 *
 */
void ackSetSourceState(struct afb_req request);

/**
 * Call "registerSource" function of Audio Manager.
 * Register source(application) to Audio Manager Policy Management
 * Application must call this function on its initialization
 *
 * #### Parameters
 *  - appname  : Application unieque name
 * [Option]
 * It is not necessary to designate following argument, because these are default value is selected y soundmanager
 * If you would like to set value, please input the following key and value
 *   - sourceClassID :
 *   - sourceState   :
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void registerSource(struct afb_req request);

/**
 * Call "deregisterSource" function of Audio Manager.
 * Deregister source(application) to Audio Manager Policy Management
 *
 * #### Parameters
 *  - sourceID  : sourceID returned in resisterSource
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void deregisterSource(struct afb_req request);

/**
 * Subscribe event
 *
 * #### Parameters
 *  - event  : Event name. Event list is written in libsoundmanager.hpp
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void subscribe(struct afb_req request);

/**
 * Unsubscribe event
 *
 * #### Parameters
 *  - event  : Event name. Event list is written in libsoundmanager.hpp
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 *
 * #### Note
 *
 */
void unsubscribe(struct afb_req request);

#ifdef ENABLE_AGL_AHL

/**
 * Application High Level API for AGL
 * This function opens "stream".
 * "stream" means the routing from source to sink.
 * This function calls registerSource and register the endpoint.
 * If the endpoint is not registered in AudioManager, Sound Manager uses default value.
 * audio_role will be translated to "sourceID", and "endpoint_id" will be translated to "sinkID".
 *
 * #### Parameters
 *  - audio_role  :   audio role such like entertainment, emergency.
 *                    This name is depends on the system architect.
 *                    The name will be application name or will be the group(role) of application.
 *  - endpoint_type:  The type of endpoint which means source/sink. As default, Sound Manager uses it as source.
 *                    sink is not supported for now.
 *  - endpoint_id :   Same as sinkID in Sound Manager.
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 * - stream_id  : Same as sourceID but key is different. This is for AHL.
 * #### Note
 * TODO : write note
 */
void streamOpen(struct afb_req req);

/**
 * Application High Level API for AGL
 * This function closes "stream".
 * This function calls disconnect with registered connectionID translated with requested connection_id.
 * If the connection is not created in Sound Manager, Sound Manager just returns with error message.
 *
 * #### Parameters
 *  - stream_id : Stream id which is returned in stream_open.
 *
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 * #### Note
 * TODO : write note
 */
void streamClose(struct afb_req req);

/**
 * Application High Level API for AGL
 * This function set stream state.
 * This function set the availability and calls connect function of Audio Manager
 * and returns the result of policy check.
 *
 * #### Parameters
 *  - stream_id : Stream id which is returned in stream_open.
 *  - mute      : Stream state as int
 * #### Return
 * - error      : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
 * #### Note
 * TODO : write note
 */
void setStreamState(struct afb_req req);

/*
********** Event list from Sound Manager **********
*/

#endif


/*
********** Application Framework Imprement **********
*/

/*
 * array of the verbs exported to afb-daemon
 */
const struct afb_verb_v2 binding_verbs[]= {
#ifdef ENABLE_AGL_AHL
// High Level API of AGL
{ .verb = "stream_open",            .callback = streamOpen,             .auth = NULL,
                .info = "Open stream." ,                 .session = AFB_SESSION_NONE},
{ .verb = "stream_close",           .callback = streamClose,            .auth = NULL,
                .info = "Close stream" ,       .session = AFB_SESSION_NONE},
{ .verb = "set_stream_state",       .callback = setStreamState,         .auth = NULL,
                .info = "Set stream state" ,             .session = AFB_SESSION_NONE},
#endif
// Adaption API of Audio Manager
{ .verb = "connect",                .callback = connect,                .auth = NULL,
                .info = "Connect source id and sink id" ,       .session = AFB_SESSION_NONE},
{ .verb = "disconnect",             .callback = disconnect,             .auth = NULL,
                .info = "Disconnect source id and sink id" ,    .session = AFB_SESSION_NONE},
{ .verb = "setVolume",              .callback = setVolume,              .auth = NULL,
                .info = "Set volume value" ,                    .session = AFB_SESSION_NONE}, /* it is better to show the range*/
{ .verb = "volumeStep",             .callback = volumeStep,             .auth = NULL,
                .info = "Set volume step range" ,               .session = AFB_SESSION_NONE},
{ .verb = "setSinkMuteState",       .callback = setSinkMuteState,       .auth = NULL,
                .info = "Set Mute state: 1 means mute, 2 means umute. Others are invalid" ,.session = AFB_SESSION_NONE},
{ .verb = "getListMainConnections", .callback = getListMainConnections, .auth = NULL,
                .info = "Get MainConnection List" ,             .session = AFB_SESSION_NONE},
{ .verb = "getListMainSinks",       .callback = getListMainSinks,       .auth = NULL,
                .info = "Get MainSink List" ,                   .session = AFB_SESSION_NONE},
{ .verb = "getListMainSources",       .callback = getListMainSources,       .auth = NULL,
                .info = "Get MainSource List" ,                 .session = AFB_SESSION_NONE},
{ .verb = "registerSource",         .callback = registerSource,         .auth = NULL,
                .info = "Register autio role" ,                 .session = AFB_SESSION_NONE},
{ .verb = "deregisterSource",       .callback = deregisterSource,       .auth = NULL,
                .info = "Deregister audio role" ,               .session = AFB_SESSION_NONE},
{ .verb = "ackConnect",             .callback = ackConnect,             .auth = NULL,
                .info = "Acknowledge of asyncConnect" ,         .session = AFB_SESSION_NONE},
{ .verb = "ackDisconnect",          .callback = ackDisconnect,          .auth = NULL,
                .info = "Acknowledge of asyncConnect" ,         .session = AFB_SESSION_NONE},
{ .verb = "ackSetSourceState",      .callback = ackSetSourceState,      .auth = NULL,
                .info = "Acknowledge of asyncSetSourceState" ,  .session = AFB_SESSION_NONE},
{ .verb = "subscribe",              .callback = subscribe,              .auth = NULL,
                .info = "Subscribe event" ,                     .session = AFB_SESSION_NONE},
{ .verb = "unsubscribe",            .callback = unsubscribe,            .auth = NULL,
                .info = "Unsubscribe event" ,                   .session = AFB_SESSION_NONE},
{ .verb = NULL } /* marker for end of the array */};

int preinit();
int sm_init();
void onevent(const char *event, struct json_object *object);

const struct afb_binding_v2 afbBindingV2 = {
    .api = "soundmanager",
    .specification = NULL,
    .verbs = binding_verbs,
    .preinit = preinit,
    .init = sm_init,
    .onevent = onevent
};

#endif //SOUNDMANAGER_H