Home --> Documentations --> PJMEDIA Reference
PJMEDIA abstraction for sound device hardware.
More...
|
pj_status_t | pjmedia_snd_init (pj_pool_factory *factory) |
|
int | pjmedia_snd_get_dev_count (void) |
|
const pjmedia_snd_dev_info * | pjmedia_snd_get_dev_info (unsigned index) |
|
pj_status_t | pjmedia_snd_set_latency (unsigned input_latency, unsigned output_latency) |
|
pj_status_t | pjmedia_snd_open (int rec_id, int play_id, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, pjmedia_snd_rec_cb rec_cb, pjmedia_snd_play_cb play_cb, void *user_data, pjmedia_snd_stream **p_snd_strm) |
|
pj_status_t | pjmedia_snd_open_rec (int index, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, pjmedia_snd_rec_cb rec_cb, void *user_data, pjmedia_snd_stream **p_snd_strm) |
|
pj_status_t | pjmedia_snd_open_player (int index, unsigned clock_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample, pjmedia_snd_play_cb play_cb, void *user_data, pjmedia_snd_stream **p_snd_strm) |
|
pj_status_t | pjmedia_snd_stream_get_info (pjmedia_snd_stream *strm, pjmedia_snd_stream_info *pi) |
|
pj_status_t | pjmedia_snd_stream_start (pjmedia_snd_stream *stream) |
|
pj_status_t | pjmedia_snd_stream_stop (pjmedia_snd_stream *stream) |
|
pj_status_t | pjmedia_snd_stream_close (pjmedia_snd_stream *stream) |
|
pj_status_t | pjmedia_snd_deinit (void) |
|
Warning: this sound device API has been deprecated and replaced by PJMEDIA Audio Device API. Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more information.
This section describes lower level abstraction for sound device hardware. Application normally uses the higher layer Sound Device Port abstraction since it works seamlessly with Media Ports Framework.
The sound hardware abstraction basically runs asychronously, and application must register callbacks to be called to receive/ supply audio frames from/to the sound hardware.
A full duplex sound stream (created with pjmedia_snd_open()) requires application to supply two callbacks:
rec_cb callback to be called when it has finished capturing one media frame, and
play_cb callback to be called when it needs media frame to be played to the sound playback hardware.
Half duplex sound stream (created with pjmedia_snd_open_rec() or pjmedia_snd_open_player()) will only need one of the callback to be specified.
After sound stream is created, application need to call pjmedia_snd_stream_start() to start capturing/playing back media frames from/to the sound device.
◆ pjmedia_snd_stream
Opaque declaration for pjmedia_snd_stream.
◆ pjmedia_snd_play_cb
typedef pj_status_t(* pjmedia_snd_play_cb) (void *user_data, pj_uint32_t timestamp, void *output, unsigned size) |
This callback is called by player stream when it needs additional data to be played by the device. Application must fill in the whole of output buffer with sound samples.
- Parameters
-
user_data | User data associated with the stream. |
timestamp | Timestamp, in samples. |
output | Buffer to be filled out by application. |
size | The size requested in bytes, which will be equal to the size of one whole packet. |
- Returns
- Non-zero to stop the stream.
◆ pjmedia_snd_rec_cb
typedef pj_status_t(* pjmedia_snd_rec_cb) (void *user_data, pj_uint32_t timestamp, void *input, unsigned size) |
This callback is called by recorder stream when it has captured the whole packet worth of audio samples.
- Parameters
-
user_data | User data associated with the stream. |
timestamp | Timestamp, in samples. |
input | Buffer containing the captured audio samples. |
size | The size of the data in the buffer, in bytes. |
- Returns
- Non-zero to stop the stream.
◆ pjmedia_snd_init()
◆ pjmedia_snd_get_dev_count()
int pjmedia_snd_get_dev_count |
( |
void |
| ) |
|
◆ pjmedia_snd_get_dev_info()
Get device info.
- Parameters
-
◆ pjmedia_snd_set_latency()
pj_status_t pjmedia_snd_set_latency |
( |
unsigned |
input_latency, |
|
|
unsigned |
output_latency |
|
) |
| |
Set sound device latency, this function must be called before sound device opened, or otherwise default latency setting will be used, - See also
- PJMEDIA_SND_DEFAULT_REC_LATENCY & PJMEDIA_SND_DEFAULT_PLAY_LATENCY.
Choosing latency value is not straightforward, it should accomodate both minimum latency and stability. Lower latency tends to cause sound device less reliable (producing audio dropouts) on CPU load disturbance. Moreover, the best latency setting may vary based on many aspects, e.g: sound card, CPU, OS, kernel, etc.
- Parameters
-
input_latency | The latency of input device, in ms, set to 0 for default PJMEDIA_SND_DEFAULT_REC_LATENCY. |
output_latency | The latency of output device, in ms, set to 0 for default PJMEDIA_SND_DEFAULT_PLAY_LATENCY. |
- Returns
- PJ_SUCCESS on success.
◆ pjmedia_snd_open()
Create sound stream for both capturing audio and audio playback, from the same device. This is the recommended way to create simultaneous recorder and player streams (instead of creating separate capture and playback streams), because it works on backends that does not allow a device to be opened more than once.
- Parameters
-
rec_id | Device index for recorder/capture stream, or -1 to use the first capable device. |
play_id | Device index for playback stream, or -1 to use the first capable device. |
clock_rate | Sound device's clock rate to set. |
channel_count | Set number of channels, 1 for mono, or 2 for stereo. The channel count determines the format of the frame. |
samples_per_frame | Number of samples per frame. |
bits_per_sample | Set the number of bits per sample. The normal value for this parameter is 16 bits per sample. |
rec_cb | Callback to handle captured audio samples. |
play_cb | Callback to be called when the sound player needs more audio samples to play. |
user_data | User data to be associated with the stream. |
p_snd_strm | Pointer to receive the stream instance. |
- Returns
- PJ_SUCCESS on success.
◆ pjmedia_snd_open_rec()
Create a unidirectional audio stream for capturing audio samples from the sound device.
- Parameters
-
index | Device index, or -1 to let the library choose the first available device. |
clock_rate | Sound device's clock rate to set. |
channel_count | Set number of channels, 1 for mono, or 2 for stereo. The channel count determines the format of the frame. |
samples_per_frame | Number of samples per frame. |
bits_per_sample | Set the number of bits per sample. The normal value for this parameter is 16 bits per sample. |
rec_cb | Callback to handle captured audio samples. |
user_data | User data to be associated with the stream. |
p_snd_strm | Pointer to receive the stream instance. |
- Returns
- PJ_SUCCESS on success.
◆ pjmedia_snd_open_player()
Create a unidirectional audio stream for playing audio samples to the sound device.
- Parameters
-
index | Device index, or -1 to let the library choose the first available device. |
clock_rate | Sound device's clock rate to set. |
channel_count | Set number of channels, 1 for mono, or 2 for stereo. The channel count determines the format of the frame. |
samples_per_frame | Number of samples per frame. |
bits_per_sample | Set the number of bits per sample. The normal value for this parameter is 16 bits per sample. |
play_cb | Callback to be called when the sound player needs more audio samples to play. |
user_data | User data to be associated with the stream. |
p_snd_strm | Pointer to receive the stream instance. |
- Returns
- PJ_SUCCESS on success.
◆ pjmedia_snd_stream_get_info()
Get information about live stream.
- Parameters
-
strm | The stream to be queried. |
pi | Pointer to stream information to be filled up with information about the stream. |
- Returns
- PJ_SUCCESS on success or the appropriate error code.
◆ pjmedia_snd_stream_start()
Start the stream.
- Parameters
-
stream | The recorder or player stream. |
- Returns
- Zero on success.
◆ pjmedia_snd_stream_stop()
Stop the stream.
- Parameters
-
stream | The recorder or player stream. |
- Returns
- Zero on success.
◆ pjmedia_snd_stream_close()
Destroy the stream.
- Parameters
-
stream | The recorder of player stream. |
- Returns
- Zero on success.
◆ pjmedia_snd_deinit()
PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.
|