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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*-*- Mode: C; c-basic-offset: 8 -*-*/

/***
  This file is part of libkanberra.

  Copyright 2008 Lennart Poettering

  libkanberra is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 2.1 of the
  License, or (at your option) any later version.

  libkanberra is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with libkanberra. If not, see
  <http://www.gnu.org/licenses/>.
***/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdarg.h>

#include "kanberra.h"
#include "common.h"
#include "malloc.h"
#include "driver.h"
#include "proplist.h"
#include "macro.h"
#include "fork-detect.h"

/**
 * SECTION:kanberra
 * @short_description: General libkanberra API
 *
 * libkanberra defines a simple abstract interface for playing event sounds.
 *
 * libkanberra relies on the XDG sound naming specification for
 * identifying event sounds. On Unix/Linux the right sound to play is
 * found via the mechanisms defined in the XDG sound themeing
 * specification. On other systems the XDG sound name is translated to
 * the native sound id for the operating system.
 *
 * An event sound is triggered via libkanberra by calling the
 * ka_context_play() function on a previously created ka_context
 * object. The ka_context_play() takes a list of key-value pairs that
 * describe the event sound to generate as closely as possible. The
 * most important property is %KA_PROP_EVENT_ID which defines the XDG
 * sound name for the sound to play.
 *
 * libkanberra is not a generic event abstraction system. It's only
 * purpose is playing sounds -- however in a very elaborate way. As
 * much information about the context the sound is triggered from
 * shall be supplied to the sound system as possible, so that it can
 * replace the sound with some other kind of feedback for a11y
 * cases. Also this additional information can be used to enhance user
 * experience (e.g. by positioning sounds in space depending on the
 * place on the screen the sound was triggered from, and similar
 * uses).
 *
 * The set of properties defined for event sounds is extensible and
 * shared with other audio systems, such as PulseAudio. Some of
 * the properties that may be set are specific to an application, to a
 * window, to an input event or to the media being played back.
 *
 * The user can attach a set of properties to the context itself,
 * which is than automatically inherited by each sample being played
 * back. (ka_context_change_props()).
 *
 * Some of the properties can be filled in by libkanberra or one of
 * its backends automatically and thus need not be be filled in by the
 * application (such as %KA_PROP_APPLICATION_PROCESS_ID and
 * friends). However the application can always overwrite any of these
 * implicit properties.
 *
 * libkanberra is thread-safe and OOM-safe (as far as the backend
 * allows this). It is not async-signal safe.
 *
 * Most libkanberra functions return an integer that indicates success
 * when 0 (%KA_SUCCESS) or an error when negative. In the latter case
 * ka_strerror() can be used to convert this code into a human
 * readable string.
 *
 * libkanberra property names need to be in 7bit ASCII, string
 * property values UTF8.
 *
 * Optionally a libkanberra backend can support caching of sounds in a
 * sound system. If this functionality is used, the latencies for
 * event sound playback can be much smaller and fewer resources are
 * needed to start playback. If a backend does not support cacheing,
 * the respective functions will return an error code of
 * %KA_ERROR_NOTSUPPORTED.
 *
 * It is highly recommended that the application sets the
 * %KA_PROP_APPLICATION_NAME, %KA_PROP_APPLICATION_ID,
 * %KA_PROP_APPLICATION_ICON_NAME/%KA_PROP_APPLICATION_ICON properties
 * immediately after creating the ka_context, before calling
 * ka_context_open() or ka_context_play().
 *
 * Its is highly recommended to pass at least %KA_PROP_EVENT_ID,
 * %KA_PROP_EVENT_DESCRIPTION to ka_context_play() for each event
 * sound generated. For sound events based on mouse inputs events
 * %KA_PROP_EVENT_MOUSE_X, %KA_PROP_EVENT_MOUSE_Y, %KA_PROP_EVENT_MOUSE_HPOS,
 * %KA_PROP_EVENT_MOUSE_VPOS, %KA_PROP_EVENT_MOUSE_BUTTON should be
 * passed. For sound events attached to a widget on the screen, the
 * %KA_PROP_WINDOW_xxx properties should be set.
 *
 *
 */

/**
 * ka_context_create:
 * @c: A pointer wheere to fill in the newly created context object.
 *
 * Create an (unconnected) context object. This call will not connect
 * to the sound system, calling this function might even suceed if no
 * working driver backend is available. To find out if one is
 * available call ka_context_open().
 *
 * Returns: 0 on success, negative error code on error.
 */

int ka_context_create(ka_context **_c) {
        ka_context *c;
        int ret;
        const char *d;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(_c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        if (!(c = ka_new0(ka_context, 1)))
                return KA_ERROR_OOM;

        if (!(c->mutex = ka_mutex_new())) {
                ka_context_destroy(c);
                return KA_ERROR_OOM;
        }

        if ((ret = ka_proplist_create(&c->props)) < 0) {
                ka_context_destroy(c);
                return ret;
        }

        if ((d = getenv("KANBERRA_DRIVER"))) {
                if ((ret = ka_context_set_driver(c, d)) < 0) {
                        ka_context_destroy(c);
                        return ret;
                }
        }

        if ((d = getenv("KANBERRA_DEVICE"))) {
                if ((ret = ka_context_change_device(c, d)) < 0) {
                        ka_context_destroy(c);
                        return ret;
                }
        }

        *_c = c;
        return KA_SUCCESS;
}

/**
 * ka_context_destroy:
 * @c: the context to destroy.
 *
 * Destroy a (connected or unconnected) context object.
 *
 * Returns: 0 on success, negative error code on error.
 */
int ka_context_destroy(ka_context *c) {
        int ret = KA_SUCCESS;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        /* There's no locking necessary here, because the application is
         * broken anyway if it destructs this object in one thread and
         * still is calling a method of it in another. */

        if (c->opened)
                ret = driver_destroy(c);

        if (c->props)
                ka_assert_se(ka_proplist_destroy(c->props) == KA_SUCCESS);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        if (c->mutex)
                ka_mutex_free(c->mutex);

        ka_free(c->driver);
        ka_free(c->device);
        ka_free(c);

        return ret;
}

/**
 * ka_context_set_driver:
 * @c: the context to change the backend driver for
 * @driver: the backend driver to use (e.g. "alsa", "pulse", "null", ...)
 *
 * Specify the backend driver used. This function may not be called again after
 * ka_context_open() suceeded. This function might suceed even when
 * the specified driver backend is not available. Use
 * ka_context_open() to find out whether the backend is available.
 *
 * Returns: 0 on success, negative error code on error.
 */
int ka_context_set_driver(ka_context *c, const char *driver) {
        char *n;
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_mutex_lock(c->mutex);
        ka_return_val_if_fail_unlock(!c->opened, KA_ERROR_STATE, c->mutex);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        if (!driver)
                n = NULL;
        else if (!(n = ka_strdup(driver))) {
                ret = KA_ERROR_OOM;
                goto fail;
        }

        ka_free(c->driver);
        c->driver = n;

        ret = KA_SUCCESS;

fail:
        ka_mutex_unlock(c->mutex);

        return ret;
}

/**
 * ka_context_change_device:
 * @c: the context to change the backend device for
 * @device: the backend device to use, in a format that is specific to the backend.
 *
 * Specify the backend device to use. This function may be called not be called after
 * ka_context_open() suceeded. This function might suceed even when
 * the specified driver backend is not available. Use
 * ka_context_open() to find out whether the backend is available
 *
 * Depending on the backend use this might or might not cause all
 * currently playing event sounds to be moved to the new device..
 *
 * Returns: 0 on success, negative error code on error.
 */
int ka_context_change_device(ka_context *c, const char *device) {
        char *n;
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_mutex_lock(c->mutex);

        if (!device)
                n = NULL;
        else if (!(n = ka_strdup(device))) {
                ret = KA_ERROR_OOM;
                goto fail;
        }

        ret = c->opened ? driver_change_device(c, n) : KA_SUCCESS;

        if (ret == KA_SUCCESS) {
                ka_free(c->device);
                c->device = n;
        } else
                ka_free(n);

fail:
        ka_mutex_unlock(c->mutex);

        return ret;
}

static int context_open_unlocked(ka_context *c) {
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        if (c->opened)
                return KA_SUCCESS;

        if ((ret = driver_open(c)) == KA_SUCCESS)
                c->opened = TRUE;

        return ret;
}

/**
 * ka_context_open:
 * @c: the context to connect.
 *
 * Connect the context to the sound system. This call is implicitly
 * called in ka_context_play() or ka_context_cache() if not called
 * explicitly. It is recommended to initialize application properties
 * with ka_context_change_props() before calling this function.
 *
 * Returns: 0 on success, negative error code on error.
 */
int ka_context_open(ka_context *c) {
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_mutex_lock(c->mutex);
        ka_return_val_if_fail_unlock(!c->opened, KA_ERROR_STATE, c->mutex);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ret = context_open_unlocked(c);

        ka_mutex_unlock(c->mutex);

        return ret;
}

/**
 * ka_context_change_props:
 * @c: the context to set the properties on.
 * @...: the list of string pairs for the properties. Needs to be a NULL terminated list.
 *
 * Write one or more string properties to the context object. Requires
 * final NULL sentinel. Properties set like this will be attached to
 * both the client object of the sound server and to all event sounds
 * played or cached. It is recommended to call this function at least
 * once before calling ka_context_open(), so that the initial
 * application properties are set properly before the initial
 * connection to the sound system. This function can be called both
 * before and after the ka_context_open() call. Properties that have
 * already been set before will be overwritten.
 *
 * Returns: 0 on success, negative error code on error.
 */

int ka_context_change_props(ka_context *c, ...)  {
        va_list ap;
        int ret;
        ka_proplist *p = NULL;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        va_start(ap, c);
        ret = ka_proplist_from_ap(&p, ap);
        va_end(ap);

        if (ret < 0)
                return ret;

        ret = ka_context_change_props_full(c, p);

        ka_assert_se(ka_proplist_destroy(p) == 0);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        return ret;
}

/**
 * ka_context_change_props_full:
 * @c: the context to set the properties on.
 * @p: the property list to set.
 *
 * Similar to ka_context_change_props(), but takes a ka_proplist
 * instead of a variable list of properties. Can be used to set binary
 * properties such as %KA_PROP_APPLICATION_ICON.
 *
 * Returns: 0 on success, negative error code on error.
 */

int ka_context_change_props_full(ka_context *c, ka_proplist *p) {
        int ret;
        ka_proplist *merged;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(p, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ka_mutex_lock(c->mutex);

        if ((ret = ka_proplist_merge(&merged, c->props, p)) < 0)
                goto finish;

        ret = c->opened ? driver_change_props(c, p, merged) : KA_SUCCESS;

        if (ret == KA_SUCCESS) {
                ka_assert_se(ka_proplist_destroy(c->props) == KA_SUCCESS);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
                c->props = merged;
        } else
                ka_assert_se(ka_proplist_destroy(merged) == KA_SUCCESS);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

finish:

        ka_mutex_unlock(c->mutex);

        return ret;
}

/**
 * ka_context_play:
 * @c: the context to play the event sound on
 * @id: an integer id this sound can later be identified with when calling ka_context_cancel()
 * @...: additional properties for this sound event.
 *
 * Play one event sound. id can be any numeric value which later can
 * be used to cancel an event sound that is currently being
 * played. You may use the same id twice or more times if you want to
 * cancel multiple event sounds with a single ka_context_cancel() call
 * at once. It is recommended to pass 0 for the id if the event sound
 * shall never be canceled. If the requested sound is not cached in
 * the server yet this call might result in the sample being uploaded
 * temporarily or permanently (this may be controlled with %KA_PROP_KANBERRA_CACHE_CONTROL). This function will start playback
 * in the background. It will not wait until playback
 * completed. Depending on the backend used a sound that is started
 * shortly before your application terminates might or might not continue to
 * play after your application terminated. If you want to make sure
 * that all sounds finish to play you need to wait synchronously for
 * the callback function of ka_context_play_full() to be called before you
 * terminate your application.
 *
 * The sample to play is identified by the %KA_PROP_EVENT_ID
 * property. If it is already cached in the server the cached version
 * is played. The properties passed in this call are merged with the
 * properties supplied when the sample was cached (if applicable)
 * and the context properties as set with ka_context_change_props().
 *
 * If %KA_PROP_EVENT_ID is not defined the sound file passed in the
 * %KA_PROP_MEDIA_FILENAME is played.
 *
 * On Linux/Unix the right sound to play is determined according to
 * %KA_PROP_EVENT_ID,
 * %KA_PROP_APPLICATION_LANGUAGE/%KA_PROP_MEDIA_LANGUAGE, the system
 * locale, %KA_PROP_KANBERRA_XDG_THEME_NAME and
 * %KA_PROP_KANBERRA_XDG_THEME_OUTPUT_PROFILE, following the XDG Sound
 * Theming Specification. On non-Unix systems the native event sound
 * that matches the XDG sound name in %KA_PROP_EVENT_ID is played.
 *
 * Returns: 0 on success, negative error code on error.
 */

int ka_context_play(ka_context *c, uint32_t id, ...) {
        int ret;
        va_list ap;
        ka_proplist *p = NULL;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        va_start(ap, id);
        ret = ka_proplist_from_ap(&p, ap);
        va_end(ap);

        if (ret < 0)
                return ret;

        ret = ka_context_play_full(c, id, p, NULL, NULL);

        ka_assert_se(ka_proplist_destroy(p) == 0);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        return ret;
}

/**
 * ka_context_play_full:
 * @c: the context to play the event sound on
 * @id: an integer id this sound can be later be identified with when calling ka_context_cancel() or when the callback is called.
 * @p: A property list of properties for this event sound
 * @cb: A callback to call when this sound event sucessfully finished playing or when an error occured during playback.
 *
 * Play one event sound, and call the specified callback function when
 * completed. See ka_finish_callback_t for the semantics the callback
 * is called in. Also see ka_context_play().
 *
 * It is guaranteed that the callback is called exactly once if
 * ka_context_play_full() returns KA_SUCCESS. You thus may safely pass
 * allocated memory to the callback and assume that it is freed
 * properly.
 *
 * Returns: 0 on success, negative error code on error.
 */

int ka_context_play_full(ka_context *c, uint32_t id, ka_proplist *p, ka_finish_callback_t cb, void *userdata) {
        int ret;
        const char *t;
        ka_bool_t enabled = TRUE;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(p, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(!userdata || cb, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ka_mutex_lock(c->mutex);

        ka_return_val_if_fail_unlock(ka_proplist_contains(p, KA_PROP_EVENT_ID) ||<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
                                     ka_proplist_contains(c->props, KA_PROP_EVENT_ID) ||
                                     ka_proplist_contains(p, KA_PROP_MEDIA_FILENAME) ||
                                     ka_proplist_contains(c->props, KA_PROP_MEDIA_FILENAME), KA_ERROR_INVALID, c->mutex);

        ka_mutex_lock(c->props->mutex);
        if ((t = ka_proplist_gets_unlocked(c->props, KA_PROP_KANBERRA_ENABLE)))
                enabled = !ka_streq(t, "0");
        ka_mutex_unlock(c->props->mutex);

        ka_mutex_lock(p->mutex);
        if ((t = ka_proplist_gets_unlocked(p, KA_PROP_KANBERRA_ENABLE)))
                enabled = !ka_streq(t, "0");
        ka_mutex_unlock(p->mutex);

        ka_return_val_if_fail_unlock(enabled, KA_ERROR_DISABLED, c->mutex);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        if ((ret = context_open_unlocked(c)) < 0)
                goto finish;

        ka_assert(c->opened);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ret = driver_play(c, id, p, cb, userdata);

finish:

        ka_mutex_unlock(c->mutex);

        return ret;
}

/**
 *
 * ka_context_cancel:
 * @c: the context to cancel the sounds on
 * @id: the id that identify the sounds to cancel.
 *
 * Cancel one or more event sounds that have been started via
 * ka_context_play(). If the sound was started with
 * ka_context_play_full() and a callback function was passed this
 * might cause this function to be called with %KA_ERROR_CANCELED as
 * error code.
 *
 * Returns: 0 on success, negative error code on error.
 */
int ka_context_cancel(ka_context *c, uint32_t id)  {
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_mutex_lock(c->mutex);
        ka_return_val_if_fail_unlock(c->opened, KA_ERROR_STATE, c->mutex);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ret = driver_cancel(c, id);

        ka_mutex_unlock(c->mutex);

        return ret;
}

/**
 * ka_context_cache:
 * @c: The context to use for uploading.
 * @...: The properties for this event sound. Terminated with NULL.
 *
 * Upload the specified sample into the audio server and attach the
 * specified properties to it. This function will only return after
 * the sample upload was finished.
 *
 * The sound to cache is found with the same algorithm that is used to
 * find the sounds for ka_context_play().
 *
 * If the backend doesn't support caching sound samples this function
 * will return %KA_ERROR_NOTSUPPORTED.
 *
 * Returns: 0 on success, negative error code on error.
 */

int ka_context_cache(ka_context *c, ...) {
        int ret;
        va_list ap;
        ka_proplist *p = NULL;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        va_start(ap, c);
        ret = ka_proplist_from_ap(&p, ap);
        va_end(ap);

        if (ret < 0)
                return ret;

        ret = ka_context_cache_full(c, p);

        ka_assert_se(ka_proplist_destroy(p) == 0);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        return ret;
}

/**
 * ka_context_cache_full:
 * @c: The context to use for uploading.
 * @p: The property list for this event sound.
 *
 * Upload the specified sample into the server and attach the
 * specified properties to it. Similar to ka_context_cache() but takes
 * a ka_proplist instead of a variable number of arguments.
 *
 * If the backend doesn't support caching sound samples this function
 * will return KA_ERROR_NOTSUPPORTED.
 *
 * Returns: 0 on success, negative error code on error.
 */
int ka_context_cache_full(ka_context *c, ka_proplist *p) {
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(p, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ka_mutex_lock(c->mutex);

        ka_return_val_if_fail_unlock(ka_proplist_contains(p, KA_PROP_EVENT_ID) ||<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
                                     ka_proplist_contains(c->props, KA_PROP_EVENT_ID), KA_ERROR_INVALID, c->mutex);

        if ((ret = context_open_unlocked(c)) < 0)
                goto finish;

        ka_assert(c->opened);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ret = driver_cache(c, p);

finish:

        ka_mutex_unlock(c->mutex);

        return ret;
}

/**
 * ka_strerror:
 * @code: Numerical error code as returned by a libkanberra API function
 *
 * Converts a numerical error code as returned by most libkanberra API functions into a human readable error string.
 *
 * Returns: a human readable error string.
 */
const char *ka_strerror(int code) {

        const char * const error_table[-_KA_ERROR_MAX] = {
                [-KA_SUCCESS] = "Success",
                [-KA_ERROR_NOTSUPPORTED] = "Operation not supported",
                [-KA_ERROR_INVALID] = "Invalid argument",
                [-KA_ERROR_STATE] = "Invalid state",
                [-KA_ERROR_OOM] = "Out of memory",
                [-KA_ERROR_NODRIVER] = "No such driver",
                [-KA_ERROR_SYSTEM] = "System error",
                [-KA_ERROR_CORRUPT] = "File or data corrupt",
                [-KA_ERROR_TOOBIG] = "File or data too large",
                [-KA_ERROR_NOTFOUND] = "File or data not found",
                [-KA_ERROR_DESTROYED] = "Destroyed",
                [-KA_ERROR_CANCELED] = "Canceled",
                [-KA_ERROR_NOTAVAILABLE] = "Not available",
                [-KA_ERROR_ACCESS] = "Access forbidden",
                [-KA_ERROR_IO] = "IO error",
                [-KA_ERROR_INTERNAL] = "Internal error",
                [-KA_ERROR_DISABLED] = "Sound disabled",
                [-KA_ERROR_FORKED] = "Process forked",
                [-KA_ERROR_DISCONNECTED] = "Disconnected"
        };

        ka_return_val_if_fail(code <= 0, NULL);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(code > _KA_ERROR_MAX, NULL);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        return error_table[-code];
}

/* Not exported */
int ka_parse_cache_control(ka_cache_control_t *control, const char *c) {
        ka_return_val_if_fail(control, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        if (ka_streq(c, "never"))
                *control = KA_CACHE_CONTROL_NEVER;
        else if (ka_streq(c, "permanent"))
                *control = KA_CACHE_CONTROL_PERMANENT;
        else if (ka_streq(c, "volatile"))
                *control = KA_CACHE_CONTROL_VOLATILE;
        else
                return KA_ERROR_INVALID;

        return KA_SUCCESS;
}

/**
 * ka_context_playing:
 * @c: the context to check if sound is still playing
 * @id: the id that identify the sounds to check
 * @playing: a pointer to a boolean that will be updated with the play status
 *
 * Check if at least one sound with the specified id is still
 * playing. Returns 0 in *playing if no sound with this id is playing
 * anymore or non-zero if there is at least one playing.
 *
 * Returns: 0 on success, negative error code on error.
 * Since: 0.16
 */
int ka_context_playing(ka_context *c, uint32_t id, int *playing)  {
        int ret;

        ka_return_val_if_fail(!ka_detect_fork(), KA_ERROR_FORKED);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(c, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_return_val_if_fail(playing, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
        ka_mutex_lock(c->mutex);
        ka_return_val_if_fail_unlock(c->opened, KA_ERROR_STATE, c->mutex);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.

        ret = driver_playing(c, id, playing);

        ka_mutex_unlock(c->mutex);

        return ret;
}