Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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 #include "asterisk/format.h"
28 
29 #if defined(__cplusplus) || defined(c_plusplus)
30 extern "C" {
31 #endif
32 
33 #define AST_SLINFACTORY_MAX_HOLD 1280
34 
36  AST_LIST_HEAD_NOLOCK(, ast_frame) queue; /*!< A list of unaltered frames */
37  struct ast_trans_pvt *trans; /*!< Translation path that converts fed frames into signed linear */
38  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) */
39  short *offset; /*!< Offset into the hold where audio begins */
40  size_t holdlen; /*!< Number of samples currently in the hold */
41  unsigned int size; /*!< Number of samples currently in the factory */
42  struct ast_format *format; /*!< Current format the translation path is converting from */
43  struct ast_format *output_format; /*!< The output format desired */
44 };
45 
46 /*!
47  * \brief Initialize a slinfactory
48  *
49  * \param sf The slinfactory to initialize
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 slin_out the slinear output format desired.
58  *
59  * \retval 0 on success
60  * \retval non-zero on failure
61  */
62 int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, struct ast_format *slin_out);
63 
64 /*!
65  * \brief Destroy the contents of a slinfactory
66  *
67  * \param sf The slinfactory that is no longer needed
68  *
69  * This function will free any memory allocated for the contents of the
70  * slinfactory. It does not free the slinfactory itself. If the sf is
71  * malloc'd, then it must be explicitly free'd after calling this function.
72  */
74 
75 /*!
76  * \brief Feed audio into a slinfactory
77  *
78  * \param sf The slinfactory to feed into
79  * \param f Frame containing audio to feed in
80  *
81  * \return Number of frames currently in factory
82  */
83 int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);
84 
85 /*!
86  * \brief Read samples from a slinfactory
87  *
88  * \param sf The slinfactory to read from
89  * \param buf Buffer to put samples into
90  * \param samples Number of samples wanted
91  *
92  * \return Number of samples read
93  */
94 int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples);
95 
96 /*!
97  * \brief Retrieve number of samples currently in a slinfactory
98  *
99  * \param sf The slinfactory to peek into
100  *
101  * \return Number of samples in slinfactory
102  */
103 unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf);
104 
105 /*!
106  * \brief Flush the contents of a slinfactory
107  *
108  * \param sf The slinfactory to flush
109  */
110 void ast_slinfactory_flush(struct ast_slinfactory *sf);
111 
112 #if defined(__cplusplus) || defined(c_plusplus)
113 }
114 #endif
115 
116 #endif /* _ASTERISK_SLINFACTORY_H */
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Media Format API.
#define AST_SLINFACTORY_MAX_HOLD
Definition: slinfactory.h:33
void ast_slinfactory_init(struct ast_slinfactory *sf)
Initialize a slinfactory.
Definition: slinfactory.c:39
int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, struct ast_format *slin_out)
Initialize a slinfactory.
Definition: slinfactory.c:46
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
Definition: slinfactory.c:199
int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
Read samples from a slinfactory.
Definition: slinfactory.c:145
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
Definition: slinfactory.c:204
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
Feed audio into a slinfactory.
Definition: slinfactory.c:77
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
Definition: slinfactory.c:58
Definition of a media format.
Definition: format.c:43
Data structure associated with a single frame of data.
AST_LIST_HEAD_NOLOCK(, ast_frame) queue
short * offset
Definition: slinfactory.h:39
struct ast_format * output_format
Definition: slinfactory.h:43
unsigned int size
Definition: slinfactory.h:41
struct ast_format * format
Definition: slinfactory.h:42
struct ast_trans_pvt * trans
Definition: slinfactory.h:37
short hold[AST_SLINFACTORY_MAX_HOLD]
Definition: slinfactory.h:38
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:213