blob: 29467836d99c200b18c6d23c3d45b2de9361be90 [file] [log] [blame]
Alexandre Lision8af73cb2013-12-10 14:11:20 -05001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJMEDIA_WAV_PORT_H__
21#define __PJMEDIA_WAV_PORT_H__
22
23/**
24 * @file wav_port.h
25 * @brief WAV file player and writer.
26 */
27#include <pjmedia/port.h>
28
29
30
31PJ_BEGIN_DECL
32
33
34/**
35 * @defgroup PJMEDIA_FILE_PLAY WAV File Player
36 * @ingroup PJMEDIA_PORT
37 * @brief Audio playback from WAV file
38 * @{
39 */
40
41/**
42 * WAV file player options.
43 */
44enum pjmedia_file_player_option
45{
46 /**
47 * Tell the file player to return NULL frame when the whole
48 * file has been played.
49 */
50 PJMEDIA_FILE_NO_LOOP = 1
51};
52
53
54/**
55 * Create a media port to play streams from a WAV file. WAV player port
56 * supports for reading WAV file with uncompressed 16 bit PCM format or
57 * compressed G.711 A-law/U-law format.
58 *
59 * @param pool Pool to create memory buffers for this port.
60 * @param filename File name to open.
61 * @param ptime The duration (in miliseconds) of each frame read
62 * from this port. If the value is zero, the default
63 * duration (20ms) will be used.
64 * @param flags Port creation flags.
65 * @param buff_size Buffer size to be allocated. If the value is zero or
66 * negative, the port will use default buffer size (which
67 * is about 4KB).
68 * @param p_port Pointer to receive the file port instance.
69 *
70 * @return PJ_SUCCESS on success.
71 */
72PJ_DECL(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool,
73 const char *filename,
74 unsigned ptime,
75 unsigned flags,
76 pj_ssize_t buff_size,
77 pjmedia_port **p_port );
78
79
80/**
81 * Get the data length, in bytes.
82 *
83 * @param port The file player port.
84 *
85 * @return The length of the data, in bytes. Upon error it will
86 * return negative value.
87 */
88PJ_DECL(pj_ssize_t) pjmedia_wav_player_get_len(pjmedia_port *port);
89
90
91/**
92 * Set the file play position of WAV player.
93 *
94 * @param port The file player port.
95 * @param offset Playback position in bytes, relative to the start of
96 * the payload.
97 *
98 * @return PJ_SUCCESS on success.
99 */
100PJ_DECL(pj_status_t) pjmedia_wav_player_port_set_pos( pjmedia_port *port,
101 pj_uint32_t offset );
102
103
104/**
105 * Get the file play position of WAV player.
106 *
107 * @param port The file player port.
108 *
109 * @return PJ_SUCCESS on success.
110 */
111PJ_DECL(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port );
112
113
114/**
115 * Register a callback to be called when the file reading has reached the
116 * end of file. If the file is set to play repeatedly, then the callback
117 * will be called multiple times. Note that only one callback can be
118 * registered for each file port.
119 *
120 * @param port The file player port.
121 * @param user_data User data to be specified in the callback
122 * @param cb Callback to be called. If the callback returns non-
123 * PJ_SUCCESS, the playback will stop. Note that if
124 * application destroys the file port in the callback,
125 * it must return non-PJ_SUCCESS here.
126 *
127 * @return PJ_SUCCESS on success.
128 */
129PJ_DECL(pj_status_t)
130pjmedia_wav_player_set_eof_cb( pjmedia_port *port,
131 void *user_data,
132 pj_status_t (*cb)(pjmedia_port *port,
133 void *usr_data));
134
135/**
136 * @}
137 */
138
139
140/**
141 * @defgroup PJMEDIA_FILE_REC File Writer (Recorder)
142 * @ingroup PJMEDIA_PORT
143 * @brief Audio capture/recording to WAV file
144 * @{
145 */
146
147
148/**
149 * WAV file writer options.
150 */
151enum pjmedia_file_writer_option
152{
153 /**
154 * Tell the file writer to save the audio in PCM format.
155 */
156 PJMEDIA_FILE_WRITE_PCM = 0,
157
158 /**
159 * Tell the file writer to save the audio in G711 Alaw format.
160 */
161 PJMEDIA_FILE_WRITE_ALAW = 1,
162
163 /**
164 * Tell the file writer to save the audio in G711 Alaw format.
165 */
166 PJMEDIA_FILE_WRITE_ULAW = 2,
167};
168
169
170/**
171 * Create a media port to record streams to a WAV file. Note that the port
172 * must be closed properly (with #pjmedia_port_destroy()) so that the WAV
173 * header can be filled with correct values (such as the file length).
174 * WAV writer port supports for writing audio in uncompressed 16 bit PCM format
175 * or compressed G.711 U-law/A-law format, this needs to be specified in
176 * \a flags param.
177 *
178 * @param pool Pool to create memory buffers for this port.
179 * @param filename File name.
180 * @param clock_rate The sampling rate.
181 * @param channel_count Number of channels.
182 * @param samples_per_frame Number of samples per frame.
183 * @param bits_per_sample Number of bits per sample (eg 16).
184 * @param flags Port creation flags, see
185 * #pjmedia_file_writer_option.
186 * @param buff_size Buffer size to be allocated. If the value is
187 * zero or negative, the port will use default buffer
188 * size (which is about 4KB).
189 * @param p_port Pointer to receive the file port instance.
190 *
191 * @return PJ_SUCCESS on success.
192 */
193PJ_DECL(pj_status_t) pjmedia_wav_writer_port_create(pj_pool_t *pool,
194 const char *filename,
195 unsigned clock_rate,
196 unsigned channel_count,
197 unsigned samples_per_frame,
198 unsigned bits_per_sample,
199 unsigned flags,
200 pj_ssize_t buff_size,
201 pjmedia_port **p_port );
202
203
204/**
205 * Get current writing position. Note that this does not necessarily match
206 * the size written to the file, since the WAV writer employs some internal
207 * buffering. Also the value reported here only indicates the payload size
208 * (it does not include the size of the WAV header),
209 *
210 * @param port The file writer port.
211 *
212 * @return Positive value to indicate the position (in bytes),
213 * or negative value containing the error code.
214 */
215PJ_DECL(pj_ssize_t) pjmedia_wav_writer_port_get_pos( pjmedia_port *port );
216
217
218/**
219 * Register the callback to be called when the file writing has reached
220 * certain size. Application can use this callback, for example, to limit
221 * the size of the output file.
222 *
223 * @param port The file writer port.
224 * @param pos The file position on which the callback will be called.
225 * @param user_data User data to be specified in the callback, and will be
226 * given on the callback.
227 * @param cb Callback to be called. If the callback returns non-
228 * PJ_SUCCESS, the writing will stop. Note that if
229 * application destroys the port in the callback, it must
230 * return non-PJ_SUCCESS here.
231 *
232 * @return PJ_SUCCESS on success.
233 */
234PJ_DECL(pj_status_t)
235pjmedia_wav_writer_port_set_cb( pjmedia_port *port,
236 pj_size_t pos,
237 void *user_data,
238 pj_status_t (*cb)(pjmedia_port *port,
239 void *usr_data));
240
241
242/**
243 * @}
244 */
245
246
247PJ_END_DECL
248
249
250#endif /* __PJMEDIA_WAV_PORT_H__ */