WARNING: The online documentation has moved to https://docs.pjsip.org.

Visit the new documentation at https://docs.pjsip.org:

BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJMEDIA Reference

File Writer (Recorder)

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

Enumerations

enum  pjmedia_file_writer_option {
  PJMEDIA_FILE_WRITE_PCM = 0 ,
  PJMEDIA_FILE_WRITE_ALAW = 1 ,
  PJMEDIA_FILE_WRITE_ULAW = 2
}
 

Functions

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))
 
pj_status_t pjmedia_wav_writer_port_set_cb2 (pjmedia_port *port, pj_size_t pos, void *user_data, void(*cb)(pjmedia_port *port, void *usr_data))
 

Detailed Description

Enumeration Type Documentation

◆ pjmedia_file_writer_option

WAV file writer options.

Enumerator
PJMEDIA_FILE_WRITE_PCM 

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

PJMEDIA_FILE_WRITE_ALAW 

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

PJMEDIA_FILE_WRITE_ULAW 

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.

Parameters
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.
Returns
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),

Parameters
portThe file writer port.
Returns
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.

Parameters
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.
Returns
PJ_SUCCESS on success.

◆ pjmedia_wav_writer_port_set_cb2()

pj_status_t pjmedia_wav_writer_port_set_cb2 ( pjmedia_port port,
pj_size_t  pos,
void *  user_data,
void(*)(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.

Parameters
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. Note that if application wishes to stop the writing, it can disconnect the port in the callback, and only after all connections have been removed could the application safely destroy the port.
Returns
PJ_SUCCESS on success.

 


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