1
/* $Id: wav_port.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#ifndef __PJMEDIA_WAV_PORT_H__
21
#define __PJMEDIA_WAV_PORT_H__
25
* @brief WAV file player and writer.
27
#include <pjmedia/port.h>
35
* @defgroup PJMEDIA_FILE_PLAY WAV File Player
36
* @ingroup PJMEDIA_PORT
37
* @brief Audio playback from WAV file
42
* WAV file player options.
44
enum pjmedia_file_player_option
47
* Tell the file player to return NULL frame when the whole
48
* file has been played.
50
PJMEDIA_FILE_NO_LOOP = 1
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.
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
68
* @param p_port Pointer to receive the file port instance.
70
* @return PJ_SUCCESS on success.
72
PJ_DECL(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool,
77
pjmedia_port **p_port );
81
* Get the data length, in bytes.
83
* @param port The file player port.
85
* @return The length of the data, in bytes. Upon error it will
86
* return negative value.
88
PJ_DECL(pj_ssize_t) pjmedia_wav_player_get_len(pjmedia_port *port);
92
* Set the file play position of WAV player.
94
* @param port The file player port.
95
* @param offset Playback position in bytes, relative to the start of
98
* @return PJ_SUCCESS on success.
100
PJ_DECL(pj_status_t) pjmedia_wav_player_port_set_pos( pjmedia_port *port,
101
pj_uint32_t offset );
105
* Get the file play position of WAV player.
107
* @param port The file player port.
109
* @return PJ_SUCCESS on success.
111
PJ_DECL(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port );
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.
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.
127
* @return PJ_SUCCESS on success.
130
pjmedia_wav_player_set_eof_cb( pjmedia_port *port,
132
pj_status_t (*cb)(pjmedia_port *port,
141
* @defgroup PJMEDIA_FILE_REC File Writer (Recorder)
142
* @ingroup PJMEDIA_PORT
143
* @brief Audio capture/recording to WAV file
149
* WAV file writer options.
151
enum pjmedia_file_writer_option
154
* Tell the file writer to save the audio in PCM format.
156
PJMEDIA_FILE_WRITE_PCM = 0,
159
* Tell the file writer to save the audio in G711 Alaw format.
161
PJMEDIA_FILE_WRITE_ALAW = 1,
164
* Tell the file writer to save the audio in G711 Alaw format.
166
PJMEDIA_FILE_WRITE_ULAW = 2,
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
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.
191
* @return PJ_SUCCESS on success.
193
PJ_DECL(pj_status_t) pjmedia_wav_writer_port_create(pj_pool_t *pool,
194
const char *filename,
196
unsigned channel_count,
197
unsigned samples_per_frame,
198
unsigned bits_per_sample,
200
pj_ssize_t buff_size,
201
pjmedia_port **p_port );
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),
210
* @param port The file writer port.
212
* @return Positive value to indicate the position (in bytes),
213
* or negative value containing the error code.
215
PJ_DECL(pj_ssize_t) pjmedia_wav_writer_port_get_pos( pjmedia_port *port );
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.
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.
232
* @return PJ_SUCCESS on success.
235
pjmedia_wav_writer_port_set_cb( pjmedia_port *port,
238
pj_status_t (*cb)(pjmedia_port *port,
250
#endif /* __PJMEDIA_WAV_PORT_H__ */