1 /**
2  * @file aucodec.c Audio Codec
3  *
4  * Copyright (C) 2010 Creytiv.com
5  */
6 
7 #include <re.h>
8 #include <baresip.h>
9 #include "core.h"
10 
11 
12 /**
13  * Register an Audio Codec
14  *
15  * @param aucodecl List of audio-codecs
16  * @param ac       Audio Codec object
17  */
aucodec_register(struct list * aucodecl,struct aucodec * ac)18 void aucodec_register(struct list *aucodecl, struct aucodec *ac)
19 {
20 	if (!aucodecl || !ac)
21 		return;
22 
23 	list_append(aucodecl, &ac->le, ac);
24 
25 	info("aucodec: %s/%u/%u\n", ac->name, ac->srate, ac->ch);
26 }
27 
28 
29 /**
30  * Unregister an Audio Codec
31  *
32  * @param ac Audio Codec object
33  */
aucodec_unregister(struct aucodec * ac)34 void aucodec_unregister(struct aucodec *ac)
35 {
36 	if (!ac)
37 		return;
38 
39 	list_unlink(&ac->le);
40 }
41 
42 
aucodec_find(const struct list * aucodecl,const char * name,uint32_t srate,uint8_t ch)43 const struct aucodec *aucodec_find(const struct list *aucodecl,
44 				   const char *name, uint32_t srate,
45 				   uint8_t ch)
46 {
47 	struct le *le;
48 
49 	for (le=list_head(aucodecl); le; le=le->next) {
50 
51 		struct aucodec *ac = le->data;
52 
53 		if (name && 0 != str_casecmp(name, ac->name))
54 			continue;
55 
56 		if (srate && srate != ac->srate)
57 			continue;
58 
59 		if (ch && ch != ac->ch)
60 			continue;
61 
62 		return ac;
63 	}
64 
65 	return NULL;
66 }
67