diff options
author | Guenter Bartsch <guenter@users.sourceforge.net> | 2001-06-24 02:19:29 +0000 |
---|---|---|
committer | Guenter Bartsch <guenter@users.sourceforge.net> | 2001-06-24 02:19:29 +0000 |
commit | 7c555ebf0b2a28279ede598eca816046ef2b0e20 (patch) | |
tree | 7f167e612703c2a4b173442d1b2d4f2f2876849d | |
parent | 5e5189033530dcbc5320d265f89d6b0fc9a836e5 (diff) | |
download | xine-lib-7c555ebf0b2a28279ede598eca816046ef2b0e20.tar.gz xine-lib-7c555ebf0b2a28279ede598eca816046ef2b0e20.tar.bz2 |
added missing metronom functions (sorry... ;-))
CVS patchset: 221
CVS date: 2001/06/24 02:19:29
-rw-r--r-- | src/audio_out/audio_oss_out.c | 6 | ||||
-rw-r--r-- | src/xine-engine/metronom.c | 201 | ||||
-rw-r--r-- | src/xine-engine/metronom.h | 4 |
3 files changed, 127 insertions, 84 deletions
diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index 19c76e066..0230741e6 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: audio_oss_out.c,v 1.15 2001/06/23 19:45:47 guenter Exp $ + * $Id: audio_oss_out.c,v 1.16 2001/06/24 02:19:29 guenter Exp $ */ /* required for swab() */ @@ -214,8 +214,8 @@ static int ao_open(ao_functions_t *this_gen, xprintf (VERBOSE|AUDIO, "audio_out : audio_step %d pts per 32768 samples\n", this->audio_step); printf ("audio_out : audio_step %d pts per 32768 samples\n", this->audio_step); - this->metronom->set_audio_rate(this->metronom, this->audio_step); - + this->metronom->set_audio_rate(this->metronom, this->audio_step); + /* * audio buffer size handling */ diff --git a/src/xine-engine/metronom.c b/src/xine-engine/metronom.c index 89a0e0567..6dbac7d92 100644 --- a/src/xine-engine/metronom.c +++ b/src/xine-engine/metronom.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: metronom.c,v 1.9 2001/06/23 19:45:47 guenter Exp $ + * $Id: metronom.c,v 1.10 2001/06/24 02:19:29 guenter Exp $ */ #ifdef HAVE_CONFIG_H @@ -44,6 +44,90 @@ #define WRAP_TRESHOLD 30000 #define MAX_NUM_WRAP_DIFF 100 + +/* + * **************************************** + * master clock feature + * **************************************** + */ + + +static void metronom_start_clock (metronom_t *this, uint32_t pts) { + + pthread_mutex_lock (&this->lock); + + gettimeofday(&this->start_time, NULL); + this->last_pts = this->start_pts = pts; + this->stopped = 0; + + pthread_mutex_unlock (&this->lock); + +} + + +static uint32_t metronom_get_current_time (metronom_t *this) { + + uint32_t pts; + struct timeval tv; + + pthread_mutex_lock (&this->lock); + + gettimeofday(&tv, NULL); + pts = (tv.tv_sec - this->start_time.tv_sec) * 90000; + pts += (tv.tv_usec - this->start_time.tv_usec) / 10 * 9 / 10; + pts += this->start_pts; + + if (this->stopped || (this->last_pts > pts)) { + /* printf("metronom: get_current_time(): timer STOPPED!\n"); */ + pts = this->last_pts; + } + + pthread_mutex_unlock (&this->lock); + + return pts; +} + + +static void metronom_stop_clock(metronom_t *this) { + + uint32_t current_time = this->get_current_time(this); + + pthread_mutex_lock (&this->lock); + + this->stopped = 1; + this->last_pts = current_time; + + pthread_mutex_unlock (&this->lock); + +} + + +static void metronom_resume_clock(metronom_t *this) { + this->start_clock(this, this->last_pts); +} + + + +static void metronom_adjust_clock(metronom_t *this, uint32_t desired_pts) +{ + int delta; + uint32_t current_time = this->get_current_time(this); + + pthread_mutex_lock (&this->lock); + + /* FIXME: this should be softer than a brute force warp... */ + delta = desired_pts; + delta -= current_time; + this->start_pts += delta; + printf("adjusting start_pts to %d\n", this->start_pts); + + pthread_mutex_unlock (&this->lock); +} + +/* + * virtual pts calculation +*/ + static void metronom_video_stream_start (metronom_t *this) { pthread_mutex_lock (&this->lock); @@ -80,6 +164,24 @@ static void metronom_video_stream_start (metronom_t *this) { metronom_start_clock (this, 0); } + +static void metronom_video_stream_end (metronom_t *this) { + + pthread_mutex_lock (&this->lock); + this->video_stream_running = 0; + + if (this->have_audio) { + while (this->audio_stream_running) { + printf ("waiting for audio to end...\n"); + pthread_cond_wait (&this->audio_ended, &this->lock); + } + } + pthread_cond_signal (&this->video_ended); + + + pthread_mutex_unlock (&this->lock); +} + static void metronom_audio_stream_start (metronom_t *this) { pthread_mutex_lock (&this->lock); @@ -113,6 +215,20 @@ static void metronom_audio_stream_start (metronom_t *this) { metronom_start_clock (this, 0); } +static void metronom_audio_stream_end (metronom_t *this) { + + pthread_mutex_lock (&this->lock); + this->audio_stream_running = 0; + while (this->video_stream_running) { + + printf ("waiting for video to start...\n"); + pthread_cond_wait (&this->video_ended, &this->lock); + } + + pthread_cond_signal (&this->audio_ended); + pthread_mutex_unlock (&this->lock); +} + static void metronom_set_video_rate (metronom_t *this, uint32_t pts_per_frame) { pthread_mutex_lock (&this->lock); @@ -346,91 +462,14 @@ static int32_t metronom_get_av_offset (metronom_t *this) { -/* - * **************************************** - * master clock feature - * **************************************** - */ - - -static void metronom_start_clock (metronom_t *this, uint32_t pts) { - - pthread_mutex_lock (&this->lock); - - gettimeofday(&this->start_time, NULL); - this->last_pts = this->start_pts = pts; - this->stopped = 0; - - pthread_mutex_unlock (&this->lock); - -} - - -static uint32_t metronom_get_current_time (metronom_t *this) { - - uint32_t pts; - struct timeval tv; - - pthread_mutex_lock (&this->lock); - - gettimeofday(&tv, NULL); - pts = (tv.tv_sec - this->start_time.tv_sec) * 90000; - pts += (tv.tv_usec - this->start_time.tv_usec) / 10 * 9 / 10; - pts += this->start_pts; - - if (this->stopped || (this->last_pts > pts)) { - /* printf("metronom: get_current_time(): timer STOPPED!\n"); */ - pts = this->last_pts; - } - - pthread_mutex_unlock (&this->lock); - - return pts; -} - - -static void metronom_stop_clock(metronom_t *this) { - - uint32_t current_time = this->get_current_time(this); - - pthread_mutex_lock (&this->lock); - - this->stopped = 1; - this->last_pts = current_time; - - pthread_mutex_unlock (&this->lock); - -} - - -static void metronom_resume_clock(metronom_t *this) { - this->start_clock(this, this->last_pts); -} - - - -static void metronom_adjust_clock(metronom_t *this, uint32_t desired_pts) -{ - int delta; - uint32_t current_time = this->get_current_time(this); - - pthread_mutex_lock (&this->lock); - - /* FIXME: this should be softer than a brute force warp... */ - delta = desired_pts; - delta -= current_time; - this->start_pts += delta; - printf("adjusting start_pts to %d\n", this->start_pts); - - pthread_mutex_unlock (&this->lock); -} - metronom_t * metronom_init (int have_audio) { metronom_t *this = xmalloc (sizeof (metronom_t)); this->audio_stream_start= metronom_audio_stream_start; + this->audio_stream_end = metronom_audio_stream_end ; this->video_stream_start= metronom_video_stream_start; + this->video_stream_end = metronom_video_stream_end ; this->set_video_rate = metronom_set_video_rate; this->get_video_rate = metronom_get_video_rate; this->set_audio_rate = metronom_set_audio_rate; @@ -448,6 +487,8 @@ metronom_t * metronom_init (int have_audio) { pthread_mutex_init (&this->lock, NULL); pthread_cond_init (&this->video_started, NULL); pthread_cond_init (&this->audio_started, NULL); + pthread_cond_init (&this->video_ended, NULL); + pthread_cond_init (&this->audio_ended, NULL); this->av_offset = 0; this->have_audio = have_audio; diff --git a/src/xine-engine/metronom.h b/src/xine-engine/metronom.h index 5fae3eb9d..6422d4f62 100644 --- a/src/xine-engine/metronom.h +++ b/src/xine-engine/metronom.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: metronom.h,v 1.4 2001/06/23 19:45:47 guenter Exp $ + * $Id: metronom.h,v 1.5 2001/06/24 02:19:29 guenter Exp $ * * metronom: general pts => virtual calculation/assoc * @@ -189,6 +189,8 @@ struct metronom_s { int audio_stream_running; pthread_cond_t video_started; pthread_cond_t audio_started; + pthread_cond_t video_ended; + pthread_cond_t audio_ended; }; |