WAV File Player
- group PJMEDIA_FILE_PLAY
Audio playback from WAV file.
Enums
-
enum pjmedia_file_player_option
WAV file player options.
Values:
-
enumerator PJMEDIA_FILE_NO_LOOP
Tell the file player to return NULL frame when the whole file has been played.
-
enumerator PJMEDIA_FILE_NO_LOCK
Disable mutex protection for getting/setting the player’s position. If the application does not access the file position, enabling this option may improve performance by avoiding unnecessary locking on each frame retrieval.
-
enumerator PJMEDIA_FILE_NO_LOOP
Functions
-
pj_status_t pjmedia_wav_player_port_create(pj_pool_t *pool, const char *filename, unsigned ptime, unsigned flags, pj_ssize_t buff_size, pjmedia_port **p_port)
Create a media port to play streams from a WAV file. WAV player port supports for reading WAV file with uncompressed 16 bit PCM format or compressed G.711 A-law/U-law format.
Note: The ptime value must be compatible with the WAV file’s sample rate. If the combination results in a fractional number of samples per frame, port creation will fail. For example, a sample rate of 22050 Hz and a frame duration (ptime) of 10 ms will result in 220.5 samples per frame, which is not an integer, so port creation will fail.
- Parameters:
pool – Pool to create memory buffers for this port.
filename – File name to open.
ptime – The duration (in miliseconds) of each frame read from this port. If the value is zero, the default duration (20ms) will be used.
flags – Port creation flags.
buff_size – Buffer size to be allocated. If the value is zero or negative, the port will use default buffer size (which is about 4KB).
p_port – Pointer to receive the file port instance.
- Returns:
PJ_SUCCESS on success.
-
pj_status_t pjmedia_wav_player_get_info(pjmedia_port *port, pjmedia_wav_player_info *i)
Get additional info about the file player.
- Parameters:
port – The file port.
i – The info.
- Returns:
PJ_SUCCESS on success or the appropriate error code.
-
pj_ssize_t pjmedia_wav_player_get_len(pjmedia_port *port)
Get the data length, in bytes.
- Parameters:
port – The file player port.
- Returns:
The length of the data, in bytes. On error, the error code is given as negative value.
-
pj_status_t pjmedia_wav_player_port_set_pos(pjmedia_port *port, pj_uint32_t offset)
Set the file play position of WAV player.
Safety: if the player is created with PJMEDIA_FILE_NO_LOCK option, this function can only be called when the player is not running (that is: get_frame() is not being called).
See also
- Parameters:
port – The file player port.
offset – Playback position in bytes, relative to the start of the payload.
- Returns:
PJ_SUCCESS on success.
-
pj_ssize_t pjmedia_wav_player_port_get_pos(pjmedia_port *port)
Get the file play position of WAV player, in bytes.
Safety: if the player is created with PJMEDIA_FILE_NO_LOCK option, this function can only be called when the player is not running (that is: get_frame() is not being called).
See also
- Parameters:
port – The file player port.
- Returns:
The current play position, in bytes. On error, the error code is given as negative value.
-
pj_status_t pjmedia_wav_player_set_eof_cb(pjmedia_port *port, void *user_data, pj_status_t (*cb)(pjmedia_port *port, void *usr_data))
Register a callback to be called when the file reading has reached the end of file. If the file is set to play repeatedly, then the callback will be called multiple times. Note that only one callback can be registered for each file port.
- Parameters:
port – The file player port.
user_data – User data to be specified in the callback
cb – Callback to be called. If the callback returns non- PJ_SUCCESS, the playback will stop. Note that if application destroys the file port in the callback, it must return non-PJ_SUCCESS here.
- Returns:
PJ_SUCCESS on success.
-
pj_status_t pjmedia_wav_player_set_eof_cb2(pjmedia_port *port, void *user_data, void (*cb)(pjmedia_port *port, void *usr_data))
Register a callback to be called when the file reading has reached the end of file. If the file is set to play repeatedly, then the callback will be called multiple times. Note that only one callback can be registered for each file port.
- Parameters:
port – The file player port.
user_data – User data to be specified in the callback
cb – Callback to be called. Note that if application wishes to stop the playback, 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.
-
struct pjmedia_wav_player_info
- #include <wav_port.h>
Additional information about the WAV player.
Public Members
-
pjmedia_format_id fmt_id
Format ID of the payload.
-
unsigned payload_bits_per_sample
The number of bits per sample of the file payload. For example, the value is 16 for PCM WAV and 8 for Alaw/Ulas WAV files.
-
pj_uint32_t size_bytes
The WAV payload size in bytes.
-
pj_uint32_t size_samples
The WAV payload size in samples.
-
pjmedia_format_id fmt_id
-
enum pjmedia_file_player_option