mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
pacat: allow configuration of latency in msec
This commit is contained in:
parent
544fa0b7db
commit
fb55798a3e
2 changed files with 119 additions and 25 deletions
|
|
@ -21,18 +21,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|||
USA.
|
||||
-->
|
||||
|
||||
<manpage name="pacat" section="1" desc="Play back or record raw audio streams on a PulseAudio sound server">
|
||||
<manpage name="pacat" section="1" desc="Play back or record raw or encoded audio streams on a PulseAudio sound server">
|
||||
|
||||
<synopsis>
|
||||
<cmd>paplay [<arg>options</arg>] [<arg>FILE</arg>]</cmd>
|
||||
<cmd>parecord [<arg>options</arg>] [<arg>FILE</arg>]</cmd>
|
||||
<cmd>pacat [<arg>options</arg>] [<arg>FILE</arg>]</cmd>
|
||||
<cmd>parec [<arg>options</arg>] [<arg>FILE</arg>]</cmd>
|
||||
<cmd>paplay <opt>--help</opt></cmd>
|
||||
<cmd>paplay <opt>--version</opt></cmd>
|
||||
<cmd>pamon [<arg>options</arg>] [<arg>FILE</arg>]</cmd>
|
||||
<cmd>pacat <opt>--help</opt></cmd>
|
||||
<cmd>pacat <opt>--version</opt></cmd>
|
||||
</synopsis>
|
||||
|
||||
<description>
|
||||
<p><file>pacat</file> is a simple tool for playing back or
|
||||
capturing raw audio files on a PulseAudio sound server.</p>
|
||||
capturing raw or encoded audio files on a PulseAudio sound
|
||||
server.</p>
|
||||
</description>
|
||||
|
||||
<options>
|
||||
|
|
@ -52,13 +56,13 @@ USA.
|
|||
<option>
|
||||
<p><opt>-r | --record</opt></p>
|
||||
|
||||
<optdesc><p>Capture raw audio data and write it to the specified file or to STDOUT if none is specified. If the tool is called under the name <file>parec</file> this is the default.</p></optdesc>
|
||||
<optdesc><p>Capture audio data and write it to the specified file or to STDOUT if none is specified. If the tool is called under the name <file>parec</file> this is the default.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>-p | --playback</opt></p>
|
||||
|
||||
<optdesc><p>Read raw audio data from the specified file or STDIN if none is specified, and play it back. If the tool is called under the name <file>pacat</file> this is the default.</p></optdesc>
|
||||
<optdesc><p>Read audio data from the specified file or STDIN if none is specified, and play it back. If the tool is called under the name <file>pacat</file> this is the default.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
|
|
@ -108,14 +112,17 @@ USA.
|
|||
|
||||
<optdesc><p>Capture or play back audio with the specified sample
|
||||
format. Specify one of <opt>u8</opt>, <opt>s16le</opt>,
|
||||
<opt>s16be</opt>, <opt>s32le</opt>,
|
||||
<opt>s32be</opt>, <opt>float32le</opt>, <opt>float32be</opt>,
|
||||
<opt>ulaw</opt>, <opt>alaw</opt>. Depending on the endianess of
|
||||
the CPU the
|
||||
formats <opt>s16ne</opt>, <opt>s16re</opt>, <opt>s32ne</opt>, <opt>s32re</opt>,
|
||||
<opt>float32ne</opt>, <opt>float32re</opt> (for native,
|
||||
resp. reverse endian) are available as aliases. Defaults to
|
||||
s16ne.</p></optdesc>
|
||||
<opt>s16be</opt>, <opt>s32le</opt>, <opt>s32be</opt>,
|
||||
<opt>float32le</opt>, <opt>float32be</opt>, <opt>ulaw</opt>,
|
||||
<opt>alaw</opt>, <opt>s32le</opt>, <opt>s32be</opt>,
|
||||
<opt>s24le</opt>, <opt>s24be</opt>, <opt>s24-32le</opt>,
|
||||
<opt>s24-32be</opt>. Depending on the endianess of the CPU the
|
||||
formats <opt>s16ne</opt>, <opt>s16re</opt>, <opt>s32ne</opt>,
|
||||
<opt>s32re</opt>, <opt>float32ne</opt>, <opt>float32re</opt>,
|
||||
<opt>s32ne</opt>, <opt>s32re</opt>, <opt>s24ne</opt>,
|
||||
<opt>s24re</opt>, <opt>s24-32ne</opt>, <opt>s24-32re</opt> (for
|
||||
native, resp. reverse endian) are available as aliases. Defaults
|
||||
to s16ne.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
|
|
@ -170,6 +177,65 @@ USA.
|
|||
<optdesc><p>Never remap channels. Instead of mapping channels by their name this will match them solely by their index/order.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--latency</opt><arg>=BYTES</arg></p>
|
||||
<optdesc><p>Explicitly configure the latency, with a time
|
||||
specified in bytes in the selected sample format. If left out
|
||||
the server will pick the latency, usually relatively high for
|
||||
power saving reasons. Use either this option or
|
||||
<opt>--latency-msec</opt>, but not both.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--latency-msec</opt><arg>=MSEC</arg></p>
|
||||
<optdesc><p>Explicitly configure the latency, with a time
|
||||
specified in miliseconds. If left out the server will pick the
|
||||
latency, usually relatively high for power saving reasons. Use
|
||||
either this option or <opt>--latency</opt>, but not
|
||||
both.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--process-time</opt><arg>=BYTES</arg></p>
|
||||
<optdesc><p>Explicitly configure the process time, with a time
|
||||
specified in bytes in the selected sample format. If left out
|
||||
the server will pick the process time. Use either this option or
|
||||
<opt>--process-time-msec</opt>, but not both.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--process-time-msec</opt><arg>=MSEC</arg></p>
|
||||
<optdesc><p>Explicitly configure the process time, with a time
|
||||
specified in miliseconds. If left out the server will pick the
|
||||
process time. Use either this option or <opt>--process-time</opt>,
|
||||
but not both.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--property</opt><arg>=PROPERTY=VALUE</arg></p>
|
||||
<optdesc><p>Attach a property to the client and stream. May be
|
||||
used multiple times</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--raw</opt></p>
|
||||
<optdesc><p>Play/record raw audio data. This is the default if
|
||||
this program is invoked as <cmd>pacat</cmd>, <cmd>parec</cmd> or
|
||||
<cmd>pamon</cmd>.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--file-format</opt><arg>[=FFORMAT]</arg></p>
|
||||
<optdesc><p>Play/record encoded audio data in the file format
|
||||
specified. This is the default if this program is invoked as
|
||||
<cmd>paplay</cmd> and <cmd>parecord</cmd>.</p></optdesc>
|
||||
</option>
|
||||
|
||||
<option>
|
||||
<p><opt>--list-file-formats</opt></p>
|
||||
<optdesc><p>List supported file formats.</p></optdesc>
|
||||
</option>
|
||||
|
||||
</options>
|
||||
|
||||
<section name="Authors">
|
||||
|
|
@ -178,7 +244,7 @@ USA.
|
|||
|
||||
<section name="See also">
|
||||
<p>
|
||||
<manref name="pulseaudio" section="1"/>, <manref name="paplay" section="1"/>
|
||||
<manref name="pulseaudio" section="1"/>, <manref name="pactl" section="1"/>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/log.h>
|
||||
#include <pulsecore/sndfile-util.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#define TIME_EVENT_USEC 50000
|
||||
|
||||
|
|
@ -86,6 +87,7 @@ static sf_count_t (*writef_function)(SNDFILE *_sndfile, const void *ptr, sf_coun
|
|||
static pa_stream_flags_t flags = 0;
|
||||
|
||||
static size_t latency = 0, process_time = 0;
|
||||
static int32_t latency_msec = 0, process_time_msec = 0;
|
||||
|
||||
static pa_bool_t raw = TRUE;
|
||||
static int file_format = -1;
|
||||
|
|
@ -434,19 +436,25 @@ static void context_state_callback(pa_context *c, void *userdata) {
|
|||
buffer_attr.maxlength = (uint32_t) -1;
|
||||
buffer_attr.prebuf = (uint32_t) -1;
|
||||
|
||||
if (latency > 0) {
|
||||
buffer_attr.fragsize = buffer_attr.tlength = (uint32_t) latency;
|
||||
buffer_attr.minreq = (uint32_t) process_time;
|
||||
if (latency_msec > 0) {
|
||||
buffer_attr.fragsize = buffer_attr.tlength = pa_usec_to_bytes(latency_msec * PA_USEC_PER_MSEC, &sample_spec);
|
||||
flags |= PA_STREAM_ADJUST_LATENCY;
|
||||
} else {
|
||||
buffer_attr.tlength = (uint32_t) -1;
|
||||
} else if (latency > 0) {
|
||||
buffer_attr.fragsize = buffer_attr.tlength = (uint32_t) latency;
|
||||
flags |= PA_STREAM_ADJUST_LATENCY;
|
||||
} else
|
||||
buffer_attr.fragsize = buffer_attr.tlength = (uint32_t) -1;
|
||||
|
||||
if (process_time_msec > 0) {
|
||||
buffer_attr.minreq = pa_usec_to_bytes(process_time_msec * PA_USEC_PER_MSEC, &sample_spec);
|
||||
} else if (process_time > 0)
|
||||
buffer_attr.minreq = (uint32_t) process_time;
|
||||
else
|
||||
buffer_attr.minreq = (uint32_t) -1;
|
||||
buffer_attr.fragsize = (uint32_t) -1;
|
||||
}
|
||||
|
||||
if (mode == PLAYBACK) {
|
||||
pa_cvolume cv;
|
||||
if (pa_stream_connect_playback(stream, device, latency > 0 ? &buffer_attr : NULL, flags, volume_is_set ? pa_cvolume_set(&cv, sample_spec.channels, volume) : NULL, NULL) < 0) {
|
||||
if (pa_stream_connect_playback(stream, device, &buffer_attr, flags, volume_is_set ? pa_cvolume_set(&cv, sample_spec.channels, volume) : NULL, NULL) < 0) {
|
||||
pa_log(_("pa_stream_connect_playback() failed: %s"), pa_strerror(pa_context_errno(c)));
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -634,9 +642,11 @@ static void help(const char *argv0) {
|
|||
" --no-remap Map channels by index instead of name.\n"
|
||||
" --latency=BYTES Request the specified latency in bytes.\n"
|
||||
" --process-time=BYTES Request the specified process time per request in bytes.\n"
|
||||
" --latency-msec=MSEC Request the specified latency in msec.\n"
|
||||
" --process-time-msec=MSEC Request the specified process time per request in msec.\n"
|
||||
" --property=PROPERTY=VALUE Set the specified property to the specified value.\n"
|
||||
" --raw Record/play raw PCM data.\n"
|
||||
" --file-format=FFORMAT Record/play formatted PCM data.\n"
|
||||
" --file-format[=FFORMAT] Record/play formatted PCM data.\n"
|
||||
" --list-file-formats List available file formats.\n")
|
||||
, argv0);
|
||||
}
|
||||
|
|
@ -659,7 +669,9 @@ enum {
|
|||
ARG_RAW,
|
||||
ARG_PROPERTY,
|
||||
ARG_FILE_FORMAT,
|
||||
ARG_LIST_FILE_FORMATS
|
||||
ARG_LIST_FILE_FORMATS,
|
||||
ARG_LATENCY_MSEC,
|
||||
ARG_PROCESS_TIME_MSEC
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
@ -695,6 +707,8 @@ int main(int argc, char *argv[]) {
|
|||
{"raw", 0, NULL, ARG_RAW},
|
||||
{"file-format", 2, NULL, ARG_FILE_FORMAT},
|
||||
{"list-file-formats", 0, NULL, ARG_LIST_FILE_FORMATS},
|
||||
{"latency-msec", 1, NULL, ARG_LATENCY_MSEC},
|
||||
{"process-time-msec", 1, NULL, ARG_PROCESS_TIME_MSEC},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
|
|
@ -854,6 +868,20 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
break;
|
||||
|
||||
case ARG_LATENCY_MSEC:
|
||||
if (((latency_msec = (int32_t) atoi(optarg))) <= 0) {
|
||||
pa_log(_("Invalid latency specification '%s'"), optarg);
|
||||
goto quit;
|
||||
}
|
||||
break;
|
||||
|
||||
case ARG_PROCESS_TIME_MSEC:
|
||||
if (((process_time_msec = (int32_t) atoi(optarg))) <= 0) {
|
||||
pa_log(_("Invalid process time specification '%s'"), optarg);
|
||||
goto quit;
|
||||
}
|
||||
break;
|
||||
|
||||
case ARG_PROPERTY: {
|
||||
char *t;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue