Blame test/audio_time.c

Packit 4a16fb
/*
Packit 4a16fb
 * This program only tracks the difference between system time
Packit 4a16fb
 * and audio time, as reported in snd_pcm_status(). It should be
Packit 4a16fb
 * helpful to verify the information reported by drivers.
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
#include <stdio.h>
Packit 4a16fb
#include <malloc.h>
Packit 4a16fb
#include <unistd.h>
Packit 4a16fb
#include <stdlib.h>
Packit 4a16fb
#include <string.h>
Packit 4a16fb
#include <getopt.h>
Packit 4a16fb
#include <fcntl.h>
Packit 4a16fb
#include <ctype.h>
Packit 4a16fb
#include <errno.h>
Packit 4a16fb
#include <limits.h>
Packit 4a16fb
#include <time.h>
Packit 4a16fb
#include <locale.h>
Packit 4a16fb
#include <math.h>
Packit 4a16fb
#include "../include/asoundlib.h"
Packit 4a16fb
Packit 4a16fb
static char *command;
Packit 4a16fb
static char *pcm_name = "hw:0";
Packit 4a16fb
snd_output_t *output = NULL;
Packit 4a16fb
Packit 4a16fb
static void usage(char *command)
Packit 4a16fb
{
Packit 4a16fb
	printf("Usage: %s [OPTION]... \n"
Packit 4a16fb
		"\n"
Packit 4a16fb
		"-h, --help              help\n"
Packit 4a16fb
		"-c, --capture           capture tstamps \n"
Packit 4a16fb
		"-d, --delay             add delay \n"
Packit 4a16fb
		"-D, --device=NAME       select PCM by name \n"
Packit 4a16fb
		"-p, --playback          playback tstamps \n"
Packit 4a16fb
		"-t, --ts_type=TYPE      Default(0),link(1),link_estimated(2),synchronized(3) \n"
Packit 4a16fb
		"-r, --report            show audio timestamp and accuracy validity\n"
Packit 4a16fb
		, command);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
long long timestamp2ns(snd_htimestamp_t t)
Packit 4a16fb
{
Packit 4a16fb
	long long nsec;
Packit 4a16fb
Packit 4a16fb
	nsec = t.tv_sec * 1000000000;
Packit 4a16fb
	nsec += t.tv_nsec;
Packit 4a16fb
Packit 4a16fb
	return nsec;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
long long timediff(snd_htimestamp_t t1, snd_htimestamp_t t2)
Packit 4a16fb
{
Packit 4a16fb
	long long nsec1, nsec2;
Packit 4a16fb
Packit 4a16fb
	nsec1 = timestamp2ns(t1);
Packit 4a16fb
	nsec2 = timestamp2ns(t2);
Packit 4a16fb
Packit 4a16fb
	return nsec1 - nsec2;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void _gettimestamp(snd_pcm_t *handle, snd_htimestamp_t *timestamp,
Packit 4a16fb
		   snd_htimestamp_t *trigger_timestamp,
Packit 4a16fb
		   snd_htimestamp_t *audio_timestamp,
Packit 4a16fb
		   snd_pcm_audio_tstamp_config_t  *audio_tstamp_config,
Packit 4a16fb
		   snd_pcm_audio_tstamp_report_t  *audio_tstamp_report,
Packit 4a16fb
		   snd_pcm_uframes_t *avail, snd_pcm_sframes_t *delay)
Packit 4a16fb
{
Packit 4a16fb
	int err;
Packit 4a16fb
	snd_pcm_status_t *status;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_status_alloca(&status);
Packit 4a16fb
Packit 4a16fb
	snd_pcm_status_set_audio_htstamp_config(status, audio_tstamp_config);
Packit 4a16fb
Packit 4a16fb
	if ((err = snd_pcm_status(handle, status)) < 0) {
Packit 4a16fb
		printf("Stream status error: %s\n", snd_strerror(err));
Packit 4a16fb
		exit(0);
Packit 4a16fb
	}
Packit 4a16fb
	snd_pcm_status_get_trigger_htstamp(status, trigger_timestamp);
Packit 4a16fb
	snd_pcm_status_get_htstamp(status, timestamp);
Packit 4a16fb
	snd_pcm_status_get_audio_htstamp(status, audio_timestamp);
Packit 4a16fb
	snd_pcm_status_get_audio_htstamp_report(status, audio_tstamp_report);
Packit 4a16fb
	*avail = snd_pcm_status_get_avail(status);
Packit 4a16fb
	*delay = snd_pcm_status_get_delay(status);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
#define TIMESTAMP_FREQ 8 /* Hz */
Packit 4a16fb
#define SAMPLE_FREQ 48000
Packit 4a16fb
#define PERIOD (SAMPLE_FREQ/TIMESTAMP_FREQ)
Packit 4a16fb
#define PCM_LINK        /* sync start for playback and capture */
Packit 4a16fb
#define TRACK_CAPTURE   /* dump capture timing info  */
Packit 4a16fb
#define TRACK_PLAYBACK  /* dump playback timing info */
Packit 4a16fb
/*#define TRACK_SAMPLE_COUNTS */ /* show difference between sample counters and audiotimestamps returned by driver */
Packit 4a16fb
#define PLAYBACK_BUFFERS 4
Packit 4a16fb
#define TSTAMP_TYPE	SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
int main(int argc, char *argv[])
Packit 4a16fb
{
Packit 4a16fb
	int c;
Packit 4a16fb
	int err;
Packit 4a16fb
	unsigned int i;
Packit 4a16fb
	snd_pcm_t *handle_p = NULL;
Packit 4a16fb
	snd_pcm_t *handle_c = NULL;
Packit 4a16fb
	snd_pcm_sframes_t frames;
Packit 4a16fb
	snd_htimestamp_t tstamp_c, tstamp_p;
Packit 4a16fb
	snd_htimestamp_t trigger_tstamp_c, trigger_tstamp_p;
Packit 4a16fb
	snd_htimestamp_t audio_tstamp_c, audio_tstamp_p;
Packit 4a16fb
	unsigned char buffer_p[PERIOD*4*4];
Packit 4a16fb
	unsigned char buffer_c[PERIOD*4*4];
Packit 4a16fb
Packit 4a16fb
	snd_pcm_hw_params_t *hwparams_p;
Packit 4a16fb
	snd_pcm_hw_params_t *hwparams_c;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_sw_params_t *swparams_p;
Packit 4a16fb
	snd_pcm_sw_params_t *swparams_c;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_uframes_t frame_count_c = 0;
Packit 4a16fb
	snd_pcm_uframes_t frame_count_p = 0;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_sframes_t delay_p, delay_c;
Packit 4a16fb
	snd_pcm_uframes_t avail_p, avail_c;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_audio_tstamp_config_t audio_tstamp_config_p;
Packit 4a16fb
	snd_pcm_audio_tstamp_config_t audio_tstamp_config_c;
Packit 4a16fb
	snd_pcm_audio_tstamp_report_t audio_tstamp_report_p;
Packit 4a16fb
	snd_pcm_audio_tstamp_report_t audio_tstamp_report_c;
Packit 4a16fb
Packit 4a16fb
	int option_index;
Packit 4a16fb
	static const char short_options[] = "hcpdrD:t:";
Packit 4a16fb
Packit 4a16fb
	static const struct option long_options[] = {
Packit 4a16fb
		{"capture", 0, 0, 'c'},
Packit 4a16fb
		{"delay", 0, 0, 'd'},
Packit 4a16fb
		{"device", required_argument, 0, 'D'},
Packit 4a16fb
		{"help", no_argument, 0, 'h'},
Packit 4a16fb
		{"playback", 0, 0, 'p'},
Packit 4a16fb
		{"ts_type", required_argument, 0, 't'},
Packit 4a16fb
		{"report", 0, 0, 'r'},
Packit 4a16fb
		{0, 0, 0, 0}
Packit 4a16fb
	};
Packit 4a16fb
Packit 4a16fb
	int do_delay = 0;
Packit 4a16fb
	int do_playback = 0;
Packit 4a16fb
	int do_capture = 0;
Packit 4a16fb
	int type = 0;
Packit 4a16fb
	int do_report = 0;
Packit 4a16fb
Packit 4a16fb
	while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
Packit 4a16fb
		switch (c) {
Packit 4a16fb
		case 'h':
Packit 4a16fb
			usage(command);
Packit 4a16fb
			return 0;
Packit 4a16fb
		case 'p':
Packit 4a16fb
			do_playback = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'c':
Packit 4a16fb
			do_capture = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'd':
Packit 4a16fb
			do_delay = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'D':
Packit 4a16fb
			pcm_name = optarg;
Packit 4a16fb
			break;
Packit 4a16fb
		case 't':
Packit 4a16fb
			type = atoi(optarg);
Packit 4a16fb
			break;
Packit 4a16fb
		case 'r':
Packit 4a16fb
			do_report = 1;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	memset(&audio_tstamp_config_p, 0, sizeof(snd_pcm_audio_tstamp_config_t));
Packit 4a16fb
	memset(&audio_tstamp_config_c, 0, sizeof(snd_pcm_audio_tstamp_config_t));
Packit 4a16fb
	memset(&audio_tstamp_report_p, 0, sizeof(snd_pcm_audio_tstamp_report_t));
Packit 4a16fb
	memset(&audio_tstamp_report_c, 0, sizeof(snd_pcm_audio_tstamp_report_t));
Packit 4a16fb
Packit 4a16fb
	if (do_playback) {
Packit 4a16fb
		if ((err = snd_pcm_open(&handle_p, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
Packit 4a16fb
			printf("Playback open error: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		if ((err = snd_pcm_set_params(handle_p,
Packit 4a16fb
							SND_PCM_FORMAT_S16,
Packit 4a16fb
							SND_PCM_ACCESS_RW_INTERLEAVED,
Packit 4a16fb
							2,
Packit 4a16fb
							SAMPLE_FREQ,
Packit 4a16fb
							0,
Packit 4a16fb
							4*1000000/TIMESTAMP_FREQ)) < 0) {
Packit 4a16fb
			printf("Playback open error: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		snd_pcm_hw_params_alloca(&hwparams_p);
Packit 4a16fb
/* get the current hwparams */
Packit 4a16fb
		err = snd_pcm_hw_params_current(handle_p, hwparams_p);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to determine current hwparams_p: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 0))
Packit 4a16fb
			printf("Playback supports audio compat timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 1))
Packit 4a16fb
			printf("Playback supports audio default timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 2))
Packit 4a16fb
			printf("Playback supports audio link timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 3))
Packit 4a16fb
			printf("Playback supports audio link absolute timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 4))
Packit 4a16fb
			printf("Playback supports audio link estimated timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 5))
Packit 4a16fb
			printf("Playback supports audio link synchronized timestamps\n");
Packit 4a16fb
Packit 4a16fb
		snd_pcm_sw_params_alloca(&swparams_p);
Packit 4a16fb
		/* get the current swparams */
Packit 4a16fb
		err = snd_pcm_sw_params_current(handle_p, swparams_p);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to determine current swparams_p: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		/* enable tstamp */
Packit 4a16fb
		err = snd_pcm_sw_params_set_tstamp_mode(handle_p, swparams_p, SND_PCM_TSTAMP_ENABLE);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to set tstamp mode : %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		err = snd_pcm_sw_params_set_tstamp_type(handle_p, swparams_p, TSTAMP_TYPE);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to set tstamp type : %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		/* write the sw parameters */
Packit 4a16fb
		err = snd_pcm_sw_params(handle_p, swparams_p);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to set swparams_p : %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	if (do_capture) {
Packit 4a16fb
Packit 4a16fb
		if ((err = snd_pcm_open(&handle_c, pcm_name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
Packit 4a16fb
			printf("Capture open error: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
		if ((err = snd_pcm_set_params(handle_c,
Packit 4a16fb
							SND_PCM_FORMAT_S16,
Packit 4a16fb
							SND_PCM_ACCESS_RW_INTERLEAVED,
Packit 4a16fb
							2,
Packit 4a16fb
							SAMPLE_FREQ,
Packit 4a16fb
							0,
Packit 4a16fb
							4*1000000/TIMESTAMP_FREQ)) < 0) {
Packit 4a16fb
			printf("Capture open error: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		snd_pcm_hw_params_alloca(&hwparams_c);
Packit 4a16fb
		/* get the current hwparams */
Packit 4a16fb
		err = snd_pcm_hw_params_current(handle_c, hwparams_c);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to determine current hwparams_c: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 0))
Packit 4a16fb
			printf("Capture supports audio compat timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 1))
Packit 4a16fb
			printf("Capture supports audio default timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 2))
Packit 4a16fb
			printf("Capture supports audio link timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 3))
Packit 4a16fb
			printf("Capture supports audio link absolute timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 4))
Packit 4a16fb
			printf("Capture supports audio link estimated timestamps\n");
Packit 4a16fb
		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 5))
Packit 4a16fb
			printf("Capture supports audio link synchronized timestamps\n");
Packit 4a16fb
Packit 4a16fb
		snd_pcm_sw_params_alloca(&swparams_c);
Packit 4a16fb
		/* get the current swparams */
Packit 4a16fb
		err = snd_pcm_sw_params_current(handle_c, swparams_c);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to determine current swparams_c: %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		/* enable tstamp */
Packit 4a16fb
		err = snd_pcm_sw_params_set_tstamp_mode(handle_c, swparams_c, SND_PCM_TSTAMP_ENABLE);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to set tstamp mode : %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		err = snd_pcm_sw_params_set_tstamp_type(handle_c, swparams_c, TSTAMP_TYPE);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to set tstamp type : %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		/* write the sw parameters */
Packit 4a16fb
		err = snd_pcm_sw_params(handle_c, swparams_c);
Packit 4a16fb
		if (err < 0) {
Packit 4a16fb
			printf("Unable to set swparams_c : %s\n", snd_strerror(err));
Packit 4a16fb
			goto _exit;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	if (do_playback && do_capture) {
Packit 4a16fb
#ifdef PCM_LINK
Packit 4a16fb
		if ((err = snd_pcm_link(handle_c, handle_p)) < 0) {
Packit 4a16fb
			printf("Streams link error: %s\n", snd_strerror(err));
Packit 4a16fb
			exit(0);
Packit 4a16fb
		}
Packit 4a16fb
#endif
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	if (do_playback) {
Packit 4a16fb
		i = PLAYBACK_BUFFERS;
Packit 4a16fb
		while (i--) {
Packit 4a16fb
			frames = snd_pcm_writei(handle_p, buffer_p, PERIOD);
Packit 4a16fb
			if (frames < 0) {
Packit 4a16fb
				printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
Packit 4a16fb
				goto _exit;
Packit 4a16fb
			}
Packit 4a16fb
			frame_count_p += frames;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		if (PLAYBACK_BUFFERS != 4)
Packit 4a16fb
			snd_pcm_start(handle_p);
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	if (do_capture) {
Packit 4a16fb
#ifndef PCM_LINK
Packit 4a16fb
		/* need to start capture explicitly */
Packit 4a16fb
		snd_pcm_start(handle_c);
Packit 4a16fb
#else
Packit 4a16fb
		if (!do_playback)
Packit 4a16fb
			/* need to start capture explicitly */
Packit 4a16fb
			snd_pcm_start(handle_c);
Packit 4a16fb
#endif
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	while (1) {
Packit 4a16fb
Packit 4a16fb
		if (do_capture) {
Packit 4a16fb
Packit 4a16fb
			frames = snd_pcm_wait(handle_c, -1);
Packit 4a16fb
			if (frames < 0) {
Packit 4a16fb
				printf("snd_pcm_wait failed: %s\n", snd_strerror(frames));
Packit 4a16fb
				goto _exit;
Packit 4a16fb
			}
Packit 4a16fb
Packit 4a16fb
			frames = snd_pcm_readi(handle_c, buffer_c, PERIOD);
Packit 4a16fb
			if (frames < 0) {
Packit 4a16fb
				printf("snd_pcm_readi failed: %s\n", snd_strerror(frames));
Packit 4a16fb
				goto _exit;
Packit 4a16fb
			}
Packit 4a16fb
			frame_count_c += frames;
Packit 4a16fb
Packit 4a16fb
#if defined(TRACK_CAPTURE)
Packit 4a16fb
			audio_tstamp_config_c.type_requested = type;
Packit 4a16fb
			audio_tstamp_config_c.report_delay = do_delay;
Packit 4a16fb
			_gettimestamp(handle_c, &tstamp_c, &trigger_tstamp_c,
Packit 4a16fb
				&audio_tstamp_c, &audio_tstamp_config_c, &audio_tstamp_report_c,
Packit 4a16fb
				&avail_c, &delay_c);
Packit 4a16fb
#if defined(TRACK_SAMPLE_COUNTS)
Packit 4a16fb
			curr_count_c = frame_count_c + delay_c; /* read plus queued */
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
			printf("capture: curr_count %lli driver count %lli, delta %lli\n",
Packit 4a16fb
				(long long)curr_count_c * 1000000000LL / SAMPLE_FREQ ,
Packit 4a16fb
				timestamp2ns(audio_tstamp_c),
Packit 4a16fb
				(long long)curr_count_c * 1000000000LL / SAMPLE_FREQ - timestamp2ns(audio_tstamp_c)
Packit 4a16fb
				);
Packit 4a16fb
#endif
Packit 4a16fb
			if (do_report) {
Packit 4a16fb
				if (audio_tstamp_report_c.valid == 0)
Packit 4a16fb
					printf("Audio capture timestamp report invalid - ");
Packit 4a16fb
				if (audio_tstamp_report_c.accuracy_report == 0)
Packit 4a16fb
					printf("Audio capture timestamp accuracy report invalid");
Packit 4a16fb
				printf("\n");
Packit 4a16fb
			}
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
			printf("\t capture: systime: %lli nsec, audio time %lli nsec, \tsystime delta %lli \t resolution %d ns \n", 
Packit 4a16fb
				timediff(tstamp_c, trigger_tstamp_c),
Packit 4a16fb
				timestamp2ns(audio_tstamp_c),
Packit 4a16fb
				timediff(tstamp_c, trigger_tstamp_c) - timestamp2ns(audio_tstamp_c), audio_tstamp_report_c.accuracy
Packit 4a16fb
				);
Packit 4a16fb
#endif
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
		if (do_playback) {
Packit 4a16fb
			frames = snd_pcm_writei(handle_p, buffer_p, PERIOD);
Packit 4a16fb
			if (frames < 0) {
Packit 4a16fb
				printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
Packit 4a16fb
				goto _exit;
Packit 4a16fb
			}
Packit 4a16fb
Packit 4a16fb
			frame_count_p += frames;
Packit 4a16fb
Packit 4a16fb
#if defined(TRACK_PLAYBACK)
Packit 4a16fb
Packit 4a16fb
			audio_tstamp_config_p.type_requested = type;
Packit 4a16fb
			audio_tstamp_config_p.report_delay = do_delay;
Packit 4a16fb
			_gettimestamp(handle_p, &tstamp_p, &trigger_tstamp_p,
Packit 4a16fb
				&audio_tstamp_p, &audio_tstamp_config_p, &audio_tstamp_report_p,
Packit 4a16fb
				&avail_p, &delay_p);
Packit 4a16fb
Packit 4a16fb
#if defined(TRACK_SAMPLE_COUNTS)
Packit 4a16fb
			curr_count_p = frame_count_p - delay_p; /* written minus queued */
Packit 4a16fb
Packit 4a16fb
			printf("playback: curr_count %lli driver count %lli, delta %lli\n",
Packit 4a16fb
				(long long)curr_count_p * 1000000000LL / SAMPLE_FREQ ,
Packit 4a16fb
				timestamp2ns(audio_tstamp_p),
Packit 4a16fb
				(long long)curr_count_p * 1000000000LL / SAMPLE_FREQ - timestamp2ns(audio_tstamp_p)
Packit 4a16fb
				);
Packit 4a16fb
#endif
Packit 4a16fb
			if (do_report) {
Packit 4a16fb
				if (audio_tstamp_report_p.valid == 0)
Packit 4a16fb
					printf("Audio playback timestamp report invalid - ");
Packit 4a16fb
				if (audio_tstamp_report_p.accuracy_report == 0)
Packit 4a16fb
					printf("Audio playback timestamp accuracy report invalid");
Packit 4a16fb
				printf("\n");
Packit 4a16fb
			}
Packit 4a16fb
Packit 4a16fb
			printf("playback: systime: %lli nsec, audio time %lli nsec, \tsystime delta %lli resolution %d ns\n",
Packit 4a16fb
				timediff(tstamp_p, trigger_tstamp_p),
Packit 4a16fb
				timestamp2ns(audio_tstamp_p),
Packit 4a16fb
				timediff(tstamp_p, trigger_tstamp_p) - timestamp2ns(audio_tstamp_p), audio_tstamp_report_p.accuracy
Packit 4a16fb
				);
Packit 4a16fb
#endif
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
	} /* while(1) */
Packit 4a16fb
Packit 4a16fb
_exit:
Packit 4a16fb
	if (handle_p)
Packit 4a16fb
		snd_pcm_close(handle_p);
Packit 4a16fb
	if (handle_c)
Packit 4a16fb
		snd_pcm_close(handle_c);
Packit 4a16fb
Packit 4a16fb
	return 0;
Packit 4a16fb
}