summaryrefslogtreecommitdiff
path: root/src/auplay.c
blob: 38a70106e09726caa37caae31f95cc84ac3bd7db (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
/**
 * @file auplay.c  Audio Player
 *
 * Copyright (C) 2010 Creytiv.com
 */

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


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 auplayl List of Audio Players
 * @param name    Audio Player name
 * @param alloch  Allocation handler
 *
 * @return 0 if success, otherwise errorcode
 */
int auplay_register(struct auplay **app, struct list *auplayl,
		    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 auplayl List of Audio Players
 * @param name    Name of the Audio Player to find
 *
 * @return Matching Audio Player if found, otherwise NULL
 */
const struct auplay *auplay_find(const struct list *auplayl, const char *name)
{
	struct le *le;

	for (le=list_head(auplayl); 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 auplayl List of Audio Players
 * @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, struct list *auplayl,
		 const char *name,
		 struct auplay_prm *prm, const char *device,
		 auplay_write_h *wh, void *arg)
{
	struct auplay *ap;

	ap = (struct auplay *)auplay_find(auplayl, name);
	if (!ap)
		return ENOENT;

	if (!prm->srate || !prm->ch)
		return EINVAL;

	return ap->alloch(stp, ap, prm, device, wh, arg);
}