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
|
/**
* @file g7221/decode.c G.722.1 Decode
*
* Copyright (C) 2010 Creytiv.com
*/
#include <re.h>
#include <baresip.h>
#define G722_1_EXPOSE_INTERNAL_STRUCTURES
#include <g722_1.h>
#include "g7221.h"
struct audec_state {
g722_1_decode_state_t dec;
};
int g7221_decode_update(struct audec_state **adsp, const struct aucodec *ac,
const char *fmtp)
{
const struct g7221_aucodec *g7221 = (struct g7221_aucodec *)ac;
struct audec_state *ads;
(void)fmtp;
if (!adsp || !ac)
return EINVAL;
ads = *adsp;
if (ads)
return 0;
ads = mem_alloc(sizeof(*ads), NULL);
if (!ads)
return ENOMEM;
if (!g722_1_decode_init(&ads->dec, g7221->bitrate, ac->srate)) {
mem_deref(ads);
return EPROTO;
}
*adsp = ads;
return 0;
}
int g7221_decode(struct audec_state *ads,
int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
size_t framec;
if (!ads || !sampv || !sampc || !buf)
return EINVAL;
framec = len / ads->dec.bytes_per_frame;
if (len != ads->dec.bytes_per_frame * framec)
return EPROTO;
if (*sampc < ads->dec.frame_size * framec)
return ENOMEM;
*sampc = g722_1_decode(&ads->dec, sampv, buf, (int)len);
return 0;
}
|