mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	update pacat.c for new latency API
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@649 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									920f045380
								
							
						
					
					
						commit
						53a0056cdf
					
				
					 1 changed files with 34 additions and 6 deletions
				
			
		| 
						 | 
					@ -31,6 +31,7 @@
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <getopt.h>
 | 
					#include <getopt.h>
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <polyp/polypaudio.h>
 | 
					#include <polyp/polypaudio.h>
 | 
				
			||||||
#include <polyp/mainloop.h>
 | 
					#include <polyp/mainloop.h>
 | 
				
			||||||
| 
						 | 
					@ -339,28 +340,34 @@ static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Show the current latency */
 | 
					/* Show the current latency */
 | 
				
			||||||
static void stream_get_latency_callback(pa_stream *s, const pa_latency_info *i, void *userdata) {
 | 
					static void stream_update_latency_callback(pa_stream *s, int success, void *userdata) {
 | 
				
			||||||
    pa_usec_t total;
 | 
					    pa_usec_t total;
 | 
				
			||||||
    int negative = 0;
 | 
					    int negative = 0;
 | 
				
			||||||
 | 
					    const pa_latency_info *i;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    assert(s);
 | 
					    assert(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!i) {
 | 
					    if (!success ||
 | 
				
			||||||
 | 
					        !(i = pa_stream_get_latency_info(s)) ||
 | 
				
			||||||
 | 
					        pa_stream_get_latency(s, &total, &negative) < 0) {
 | 
				
			||||||
        fprintf(stderr, "Failed to get latency: %s\n", pa_strerror(pa_context_errno(context)));
 | 
					        fprintf(stderr, "Failed to get latency: %s\n", pa_strerror(pa_context_errno(context)));
 | 
				
			||||||
        quit(1);
 | 
					        quit(1);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    total = pa_stream_get_latency(s, i, &negative);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
 | 
					    fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
 | 
				
			||||||
            (float) i->buffer_usec, (float) i->sink_usec, (float) i->source_usec, (float) i->transport_usec, (float) total * (negative?-1:1),
 | 
					            (float) i->buffer_usec,
 | 
				
			||||||
 | 
					            (float) i->sink_usec,
 | 
				
			||||||
 | 
					            (float) i->source_usec,
 | 
				
			||||||
 | 
					            (float) i->transport_usec,
 | 
				
			||||||
 | 
					            (float) total * (negative?-1:1),
 | 
				
			||||||
            i->synchronized_clocks ? "yes" : "no");
 | 
					            i->synchronized_clocks ? "yes" : "no");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Someone requested that the latency is shown */
 | 
					/* Someone requested that the latency is shown */
 | 
				
			||||||
static void sigusr1_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
 | 
					static void sigusr1_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
 | 
				
			||||||
    fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
 | 
					    fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
 | 
				
			||||||
    pa_operation_unref(pa_stream_get_latency_info(stream, stream_get_latency_callback, NULL));
 | 
					    pa_operation_unref(pa_stream_update_latency_info(stream, stream_update_latency_callback, NULL));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -511,6 +518,27 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
        fprintf(stderr, "Opening a %s stream with sample specification '%s'.\n", mode == RECORD ? "recording" : "playback", t);
 | 
					        fprintf(stderr, "Opening a %s stream with sample specification '%s'.\n", mode == RECORD ? "recording" : "playback", t);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (optind+1 < argc) {
 | 
				
			||||||
 | 
					        fprintf(stderr, "Too many arguments.\n");
 | 
				
			||||||
 | 
					        goto quit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (optind+1 == argc) {
 | 
				
			||||||
 | 
					        int fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ((fd = open(argv[optind], O_RDONLY)) < 0) {
 | 
				
			||||||
 | 
					            fprintf(stderr, "open(): %s\n", strerror(errno));
 | 
				
			||||||
 | 
					            goto quit;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (dup2(fd, 0) < 0) {
 | 
				
			||||||
 | 
					            fprintf(stderr, "dup2(): %s\n", strerror(errno));
 | 
				
			||||||
 | 
					            goto quit;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        close(fd);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    /* Set up a new main loop */
 | 
					    /* Set up a new main loop */
 | 
				
			||||||
    if (!(m = pa_mainloop_new())) {
 | 
					    if (!(m = pa_mainloop_new())) {
 | 
				
			||||||
        fprintf(stderr, "pa_mainloop_new() failed.\n");
 | 
					        fprintf(stderr, "pa_mainloop_new() failed.\n");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue