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
|
/**
* @file auplay.c Audio Player
*
* Copyright (C) 2010 Creytiv.com
*/
#include <re.h>
#include <baresip.h>
#include "core.h"
static struct list auplayl = LIST_INIT;
static void destructor(void *arg)
{
struct auplay *ap = arg;
list_unlink(&ap->le);
}
/**
* Register an Audio Player
*
* @param app Pointer to allocated Audio Player object
* @param name Audio Player name
* @param alloch Allocation handler
*
* @return 0 if success, otherwise errorcode
*/
int auplay_register(struct auplay **app, const char *name,
auplay_alloc_h *alloch)
{
struct auplay *ap;
if (!app)
return EINVAL;
ap = mem_zalloc(sizeof(*ap), destructor);
if (!ap)
return ENOMEM;
list_append(&auplayl, &ap->le, ap);
ap->name = name;
ap->alloch = alloch;
info("auplay: %s\n", name);
*app = ap;
return 0;
}
/**
* Find an Audio Player by name
*
* @param name Name of the Audio Player to find
*
* @return Matching Audio Player if found, otherwise NULL
*/
const struct auplay *auplay_find(const char *name)
{
struct le *le;
for (le=auplayl.head; le; le=le->next) {
struct auplay *ap = le->data;
if (str_isset(name) && 0 != str_casecmp(name, ap->name))
continue;
return ap;
}
return NULL;
}
/**
* Allocate an Audio Player state
*
* @param stp Pointer to allocated Audio Player state
* @param name Name of Audio Player
* @param prm Audio Player parameters
* @param device Name of Audio Player device (driver specific)
* @param wh Write handler
* @param arg Handler argument
*
* @return 0 if success, otherwise errorcode
*/
int auplay_alloc(struct auplay_st **stp, const char *name,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg)
{
struct auplay *ap;
ap = (struct auplay *)auplay_find(name);
if (!ap)
return ENOENT;
if (!prm->srate || !prm->ch)
return EINVAL;
return ap->alloch(stp, ap, prm, device, wh, arg);
}
|