Home --> Documentations --> PJMEDIA Reference

File Writer (Recorder)

Audio capture/recording to WAV file. More...


enum  pjmedia_file_writer_option {


pj_status_t pjmedia_wav_writer_port_create (pj_pool_t *pool, const char *filename, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, unsigned flags, pj_ssize_t buff_size, pjmedia_port **p_port)
pj_ssize_t pjmedia_wav_writer_port_get_pos (pjmedia_port *port)
pj_status_t pjmedia_wav_writer_port_set_cb (pjmedia_port *port, pj_size_t pos, void *user_data, pj_status_t(*cb)(pjmedia_port *port, void *usr_data))

Detailed Description

Enumeration Type Documentation

◆ pjmedia_file_writer_option

WAV file writer options.


Tell the file writer to save the audio in PCM format.


Tell the file writer to save the audio in G711 Alaw format.


Tell the file writer to save the audio in G711 Alaw format.

Function Documentation

◆ pjmedia_wav_writer_port_create()

pj_status_t pjmedia_wav_writer_port_create ( pj_pool_t pool,
const char *  filename,
unsigned  clock_rate,
unsigned  channel_count,
unsigned  samples_per_frame,
unsigned  bits_per_sample,
unsigned  flags,
pj_ssize_t  buff_size,
pjmedia_port **  p_port 

Create a media port to record streams to a WAV file. Note that the port must be closed properly (with pjmedia_port_destroy()) so that the WAV header can be filled with correct values (such as the file length). WAV writer port supports for writing audio in uncompressed 16 bit PCM format or compressed G.711 U-law/A-law format, this needs to be specified in flags param.

poolPool to create memory buffers for this port.
filenameFile name.
clock_rateThe sampling rate.
channel_countNumber of channels.
samples_per_frameNumber of samples per frame.
bits_per_sampleNumber of bits per sample (eg 16).
flagsPort creation flags, see pjmedia_file_writer_option.
buff_sizeBuffer size to be allocated. If the value is zero or negative, the port will use default buffer size (which is about 4KB).
p_portPointer to receive the file port instance.
PJ_SUCCESS on success.

◆ pjmedia_wav_writer_port_get_pos()

pj_ssize_t pjmedia_wav_writer_port_get_pos ( pjmedia_port port)

Get current writing position. Note that this does not necessarily match the size written to the file, since the WAV writer employs some internal buffering. Also the value reported here only indicates the payload size (it does not include the size of the WAV header),

portThe file writer port.
Positive value to indicate the position (in bytes), or negative value containing the error code.

◆ pjmedia_wav_writer_port_set_cb()

pj_status_t pjmedia_wav_writer_port_set_cb ( pjmedia_port port,
pj_size_t  pos,
void *  user_data,
pj_status_t(*)(pjmedia_port *port, void *usr_data)  cb 

Register the callback to be called when the file writing has reached certain size. Application can use this callback, for example, to limit the size of the output file.

portThe file writer port.
posThe file position on which the callback will be called.
user_dataUser data to be specified in the callback, and will be given on the callback.
cbCallback to be called. If the callback returns non- PJ_SUCCESS, the writing will stop. Note that if application destroys the port in the callback, it must return non-PJ_SUCCESS here.
PJ_SUCCESS on success.


PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.