summaryrefslogtreecommitdiff
path: root/include/asterisk/slinfactory.h
blob: 386cf51baed6345eb9bc0a48af8e7dcb278d59a1 (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
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2005, Anthony Minessale II
 *
 * Anthony Minessale <anthmct@yahoo.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

/*! \file
 * \brief A machine to gather up arbitrary frames and convert them
 * to raw slinear on demand.
 */

#ifndef _ASTERISK_SLINFACTORY_H
#define _ASTERISK_SLINFACTORY_H

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

struct ast_slinfactory {
	AST_LIST_HEAD_NOLOCK(, ast_frame) queue; /*!< A list of unaltered frames */
	struct ast_trans_pvt *trans;             /*!< Translation path that converts fed frames into signed linear */
	short hold[1280];                        /*!< Hold for audio that no longer belongs to a frame (ie: if only some samples were taken from a frame) */
	short *offset;                           /*!< Offset into the hold where audio begins */
	size_t holdlen;                          /*!< Number of samples currently in the hold */
	unsigned int size;                       /*!< Number of samples currently in the factory */
	unsigned int format;                     /*!< Current format the translation path is converting from */
};

/*!
 * \brief Initialize an slinfactory
 *
 * \arg sf The slinfactory to initialize
 *
 * \return Nothing
 */
void ast_slinfactory_init(struct ast_slinfactory *sf);

/*!
 * \brief Destroy the contents of a slinfactory
 *
 * \arg sf The slinfactory that is no longer needed
 *
 * This function will free any memory allocated for the contents of the
 * slinfactory.  It does not free the slinfactory itself.  If the sf is
 * malloc'd, then it must be explicitly free'd after calling this function.
 *
 * \return Nothing
 */
void ast_slinfactory_destroy(struct ast_slinfactory *sf);

/*!
 * \brief Feed audio into an slinfactory
 *
 * \arg sf The slinfactory to feed into
 * \arg f Frame containing audio to feed in
 *
 * \return Number of frames currently in factory
 */
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);

/*!
 * \brief Read samples from an slinfactory
 *
 * \arg sf The slinfactory to read from
 * \arg buf Buffer to put samples into
 * \arg samples Number of samples wanted
 *
 * \return Number of samples read
 */
int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples);

/*!
 * \brief Retrieve number of samples currently in an slinfactory
 *
 * \arg sf The slinfactory to peek into
 *
 * \return Number of samples in slinfactory
 */
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf);

/*!
 * \brief Flush the contents of an slinfactory
 *
 * \arg sf The slinfactory to flush
 *
 * \return Nothing
 */
void ast_slinfactory_flush(struct ast_slinfactory *sf);

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif /* _ASTERISK_SLINFACTORY_H */