Wed Jan 8 2020 09:49:51

Asterisk developer's documentation


slinfactory.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2005, Anthony Minessale II
5  *
6  * Anthony Minessale <anthmct@yahoo.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief A machine to gather up arbitrary frames and convert them
21  * to raw slinear on demand.
22  */
23 
24 #ifndef _ASTERISK_SLINFACTORY_H
25 #define _ASTERISK_SLINFACTORY_H
26 
27 #if defined(__cplusplus) || defined(c_plusplus)
28 extern "C" {
29 #endif
30 
31 #define AST_SLINFACTORY_MAX_HOLD 1280
32 
34  AST_LIST_HEAD_NOLOCK(, ast_frame) queue; /*!< A list of unaltered frames */
35  struct ast_trans_pvt *trans; /*!< Translation path that converts fed frames into signed linear */
36  short hold[AST_SLINFACTORY_MAX_HOLD]; /*!< Hold for audio that no longer belongs to a frame (ie: if only some samples were taken from a frame) */
37  short *offset; /*!< Offset into the hold where audio begins */
38  size_t holdlen; /*!< Number of samples currently in the hold */
39  unsigned int size; /*!< Number of samples currently in the factory */
40  format_t format; /*!< Current format the translation path is converting from */
41  format_t output_format; /*!< The output format desired */
42 };
43 
44 /*!
45  * \brief Initialize a slinfactory
46  *
47  * \param sf The slinfactory to initialize
48  *
49  * \return Nothing
50  */
51 void ast_slinfactory_init(struct ast_slinfactory *sf);
52 
53 /*!
54  * \brief Initialize a slinfactory
55  *
56  * \param sf The slinfactory to initialize
57  * \param sample_rate The output sample rate desired
58  *
59  * \return 0 on success, non-zero on failure
60  */
61 int ast_slinfactory_init_rate(struct ast_slinfactory *sf, unsigned int sample_rate);
62 
63 /*!
64  * \brief Destroy the contents of a slinfactory
65  *
66  * \param sf The slinfactory that is no longer needed
67  *
68  * This function will free any memory allocated for the contents of the
69  * slinfactory. It does not free the slinfactory itself. If the sf is
70  * malloc'd, then it must be explicitly free'd after calling this function.
71  *
72  * \return Nothing
73  */
75 
76 /*!
77  * \brief Feed audio into a slinfactory
78  *
79  * \param sf The slinfactory to feed into
80  * \param f Frame containing audio to feed in
81  *
82  * \return Number of frames currently in factory
83  */
84 int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);
85 
86 /*!
87  * \brief Read samples from a slinfactory
88  *
89  * \param sf The slinfactory to read from
90  * \param buf Buffer to put samples into
91  * \param samples Number of samples wanted
92  *
93  * \return Number of samples read
94  */
95 int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples);
96 
97 /*!
98  * \brief Retrieve number of samples currently in a slinfactory
99  *
100  * \param sf The slinfactory to peek into
101  *
102  * \return Number of samples in slinfactory
103  */
104 unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf);
105 
106 /*!
107  * \brief Flush the contents of a slinfactory
108  *
109  * \param sf The slinfactory to flush
110  *
111  * \return Nothing
112  */
113 void ast_slinfactory_flush(struct ast_slinfactory *sf);
114 
115 #if defined(__cplusplus) || defined(c_plusplus)
116 }
117 #endif
118 
119 #endif /* _ASTERISK_SLINFACTORY_H */
unsigned int size
Definition: slinfactory.h:39
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
Definition: slinfactory.c:201
short hold[AST_SLINFACTORY_MAX_HOLD]
Definition: slinfactory.h:36
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
Feed audio into a slinfactory.
Definition: slinfactory.c:77
struct ast_trans_pvt * trans
Definition: slinfactory.h:35
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
Definition: slinfactory.c:196
AST_LIST_HEAD_NOLOCK(, ast_frame) queue
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
Definition: slinfactory.c:64
int ast_slinfactory_init_rate(struct ast_slinfactory *sf, unsigned int sample_rate)
Initialize a slinfactory.
Definition: slinfactory.c:46
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:135
int64_t format_t
Definition: frame_defs.h:32
short * offset
Definition: slinfactory.h:37
format_t output_format
Definition: slinfactory.h:41
static struct ast_format f[]
Definition: format_g726.c:181
void ast_slinfactory_init(struct ast_slinfactory *sf)
Initialize a slinfactory.
Definition: slinfactory.c:39
#define AST_SLINFACTORY_MAX_HOLD
Definition: slinfactory.h:31
format_t format
Definition: slinfactory.h:40
Data structure associated with a single frame of data.
Definition: frame.h:142
int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
Read samples from a slinfactory.
Definition: slinfactory.c:142