1 /**
2 * @file ausrc.c Audio Source
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7 #include <re.h>
8 #include <baresip.h>
9 #include "core.h"
10
11
destructor(void * arg)12 static void destructor(void *arg)
13 {
14 struct ausrc *as = arg;
15
16 list_unlink(&as->le);
17 }
18
19
20 /**
21 * Register an Audio Source
22 *
23 * @param asp Pointer to allocated Audio Source object
24 * @param ausrcl List of Audio Sources
25 * @param name Audio Source name
26 * @param alloch Allocation handler
27 *
28 * @return 0 if success, otherwise errorcode
29 */
ausrc_register(struct ausrc ** asp,struct list * ausrcl,const char * name,ausrc_alloc_h * alloch)30 int ausrc_register(struct ausrc **asp, struct list *ausrcl,
31 const char *name, ausrc_alloc_h *alloch)
32 {
33 struct ausrc *as;
34
35 if (!asp)
36 return EINVAL;
37
38 as = mem_zalloc(sizeof(*as), destructor);
39 if (!as)
40 return ENOMEM;
41
42 list_append(ausrcl, &as->le, as);
43
44 as->name = name;
45 as->alloch = alloch;
46
47 info("ausrc: %s\n", name);
48
49 *asp = as;
50
51 return 0;
52 }
53
54
55 /**
56 * Find an Audio Source by name
57 *
58 * @param ausrcl List of Audio Sources
59 * @param name Name of the Audio Source to find
60 *
61 * @return Matching Audio Source if found, otherwise NULL
62 */
ausrc_find(const struct list * ausrcl,const char * name)63 const struct ausrc *ausrc_find(const struct list *ausrcl, const char *name)
64 {
65 struct le *le;
66
67 for (le=list_head(ausrcl); le; le=le->next) {
68
69 struct ausrc *as = le->data;
70
71 if (str_isset(name) && 0 != str_casecmp(name, as->name))
72 continue;
73
74 return as;
75 }
76
77 return NULL;
78 }
79
80
81 /**
82 * Allocate an Audio Source state
83 *
84 * @param stp Pointer to allocated Audio Source state
85 * @param ausrcl List of Audio Sources
86 * @param ctx Media context (optional)
87 * @param name Name of Audio Source
88 * @param prm Audio Source parameters
89 * @param device Name of Audio Source device (driver specific)
90 * @param rh Read handler
91 * @param errh Error handler
92 * @param arg Handler argument
93 *
94 * @return 0 if success, otherwise errorcode
95 */
ausrc_alloc(struct ausrc_st ** stp,struct list * ausrcl,struct media_ctx ** ctx,const char * name,struct ausrc_prm * prm,const char * device,ausrc_read_h * rh,ausrc_error_h * errh,void * arg)96 int ausrc_alloc(struct ausrc_st **stp, struct list *ausrcl,
97 struct media_ctx **ctx,
98 const char *name, struct ausrc_prm *prm, const char *device,
99 ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
100 {
101 struct ausrc *as;
102
103 as = (struct ausrc *)ausrc_find(ausrcl, name);
104 if (!as)
105 return ENOENT;
106
107 return as->alloch(stp, as, ctx, prm, device, rh, errh, arg);
108 }
109