summaryrefslogtreecommitdiff
path: root/src/ausrc.c
blob: 9782db35f03716670811a76bc253d3f1a9f7e771 (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
/**
 * @file ausrc.c Audio Source
 *
 * Copyright (C) 2010 Creytiv.com
 */

#include <re.h>
#include <baresip.h>
#include "core.h"


static struct list ausrcl = LIST_INIT;


static void destructor(void *arg)
{
	struct ausrc *as = arg;

	list_unlink(&as->le);
}


/**
 * Register an Audio Source
 *
 * @param asp     Pointer to allocated Audio Source object
 * @param name    Audio Source name
 * @param alloch  Allocation handler
 *
 * @return 0 if success, otherwise errorcode
 */
int ausrc_register(struct ausrc **asp, const char *name, ausrc_alloc_h *alloch)
{
	struct ausrc *as;

	if (!asp)
		return EINVAL;

	as = mem_zalloc(sizeof(*as), destructor);
	if (!as)
		return ENOMEM;

	list_append(&ausrcl, &as->le, as);

	as->name   = name;
	as->alloch = alloch;

	info("ausrc: %s\n", name);

	*asp = as;

	return 0;
}


/**
 * Find an Audio Source by name
 *
 * @param name Name of the Audio Source to find
 *
 * @return Matching Audio Source if found, otherwise NULL
 */
const struct ausrc *ausrc_find(const char *name)
{
	struct le *le;

	for (le=ausrcl.head; le; le=le->next) {

		struct ausrc *as = le->data;

		if (str_isset(name) && 0 != str_casecmp(name, as->name))
			continue;

		return as;
	}

	return NULL;
}


/**
 * Allocate an Audio Source state
 *
 * @param stp    Pointer to allocated Audio Source state
 * @param ctx    Media context (optional)
 * @param name   Name of Audio Source
 * @param prm    Audio Source parameters
 * @param device Name of Audio Source device (driver specific)
 * @param rh     Read handler
 * @param errh   Error handler
 * @param arg    Handler argument
 *
 * @return 0 if success, otherwise errorcode
 */
int ausrc_alloc(struct ausrc_st **stp, struct media_ctx **ctx,
		const char *name, struct ausrc_prm *prm, const char *device,
		ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
{
	struct ausrc *as;

	as = (struct ausrc *)ausrc_find(name);
	if (!as)
		return ENOENT;

	return as->alloch(stp, as, ctx, prm, device, rh, errh, arg);
}