mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05: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
				
			
		| 
						 | 
				
			
			@ -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