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
|
/**
* @file l16.c 16-bit linear codec
*
* Copyright (C) 2010 - 2015 Creytiv.com
*/
#include <re.h>
#include <baresip.h>
/**
* @defgroup l16 l16
*
* Linear 16-bit audio codec
*/
enum {NR_CODECS = 8};
static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
const int16_t *sampv, size_t sampc)
{
int16_t *p = (void *)buf;
(void)st;
if (!buf || !len || !sampv)
return EINVAL;
if (*len < sampc*2)
return ENOMEM;
*len = sampc*2;
while (sampc--)
*p++ = htons(*sampv++);
return 0;
}
static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
int16_t *p = (void *)buf;
(void)st;
if (!buf || !len || !sampv)
return EINVAL;
if (*sampc < len/2)
return ENOMEM;
*sampc = len/2;
len /= 2;
while (len--)
*sampv++ = ntohs(*p++);
return 0;
}
/* See RFC 3551 */
static struct aucodec l16v[NR_CODECS] = {
{LE_INIT, "10", "L16", 44100, 44100, 2, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, 0, "L16", 32000, 32000, 2, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, 0, "L16", 16000, 16000, 2, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, 0, "L16", 8000, 8000, 2, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, "11", "L16", 44100, 44100, 1, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, 0, "L16", 32000, 32000, 1, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, 0, "L16", 16000, 16000, 1, 0, 0, encode, 0, decode, 0, 0, 0},
{LE_INIT, 0, "L16", 8000, 8000, 1, 0, 0, encode, 0, decode, 0, 0, 0},
};
static int module_init(void)
{
struct list *aucodecl = baresip_aucodecl();
size_t i;
for (i=0; i<NR_CODECS; i++)
aucodec_register(aucodecl, &l16v[i]);
return 0;
}
static int module_close(void)
{
size_t i;
for (i=0; i<NR_CODECS; i++)
aucodec_unregister(&l16v[i]);
return 0;
}
EXPORT_SYM const struct mod_export DECL_EXPORTS(l16) = {
"l16",
"codec",
module_init,
module_close
};
|