--- /home/edward/src/mplayer/main/libao2/ao_jack.c 2005-06-17 16:08:21.000000000 +0100 +++ libao2/ao_jack.c 2005-06-17 17:32:56.000000000 +0100 @@ -46,11 +46,12 @@ static volatile int paused = 0; ///< set if paused static volatile int underrun = 0; ///< signals if an underrun occured -//! If this is defined try to make a more precise delay estimation. Will be slower. -#undef JACK_ESTIMATE_DELAY -#ifdef JACK_ESTIMATE_DELAY static volatile int callback_samples = 0; static volatile unsigned int callback_time = 0; +//! If this is defined try to make a more precise delay estimation. Will be slower. +//#define JACK_PRECISE_DELAY +#ifdef JACK_PRECISE_DELAY +static volatile unsigned int callback_predicted_time = 0; #endif //! size of one chunk, if this is too small MPlayer will start to "stutter" @@ -186,8 +187,18 @@ underrun = 1; if (paused || underrun) silence(bufs, nframes, num_ports); -#ifdef JACK_ESTIMATE_DELAY + callback_samples = nframes; +#ifdef JACK_PRECISE_DELAY + unsigned int tmp_time = GetTimer(); + callback_time = callback_predicted_time; //Predicted time + if (abs(tmp_time - callback_time) > 10000) { + callback_time = tmp_time; // Reset timer + mp_msg(MSGT_AO,MSGL_V, "Resetting predicted timer\n"); + } else if (abs(tmp_time - callback_time) > 1000) + callback_time += (tmp_time - callback_time)/20; //Adjust prediction + callback_predicted_time = callback_time + (nframes*1000000) / ao_data.samplerate; +#else callback_time = GetTimer(); #endif return 0; @@ -342,11 +353,11 @@ static float get_delay() { int buffered = BUFFSIZE - CHUNK_SIZE - buf_free(); // could be less float in_jack = jack_latency; -#ifdef JACK_ESTIMATE_DELAY + unsigned int elapsed = GetTimer() - callback_time; in_jack += (float)callback_samples / (float)ao_data.samplerate - (float)elapsed / 1000.0 / 1000.0; if (in_jack < 0) in_jack = 0; -#endif + return (float)buffered / (float)ao_data.bps + in_jack; }