summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Bartsch <guenter@users.sourceforge.net>2001-10-18 18:50:53 +0000
committerGuenter Bartsch <guenter@users.sourceforge.net>2001-10-18 18:50:53 +0000
commitc633dfb135e832a8a17c90e6a09b6e3ab49875a6 (patch)
tree340a02c99fef6e7a10077962c6b3a2b75c1dde1a
parent21cfbbe47111fb18000732363de1a30beb5850c6 (diff)
downloadxine-lib-c633dfb135e832a8a17c90e6a09b6e3ab49875a6.tar.gz
xine-lib-c633dfb135e832a8a17c90e6a09b6e3ab49875a6.tar.bz2
audio decoder cleanup, tell the audio part of metronom that there are still images so it can increment it's internal pts counters
CVS patchset: 833 CVS date: 2001/10/18 18:50:53
-rw-r--r--src/xine-engine/Makefile.am4
-rw-r--r--src/xine-engine/audio_decoder.c54
-rw-r--r--src/xine-engine/buffer.h3
-rw-r--r--src/xine-engine/lrb.c123
-rw-r--r--src/xine-engine/lrb.h54
-rw-r--r--src/xine-engine/metronom.c29
-rw-r--r--src/xine-engine/metronom.h8
-rw-r--r--src/xine-engine/video_decoder.c11
-rw-r--r--src/xine-engine/xine_internal.h4
9 files changed, 248 insertions, 42 deletions
diff --git a/src/xine-engine/Makefile.am b/src/xine-engine/Makefile.am
index 8666a6cef..8bff05047 100644
--- a/src/xine-engine/Makefile.am
+++ b/src/xine-engine/Makefile.am
@@ -11,7 +11,7 @@ lib_LTLIBRARIES = libxine.la
libxine_la_SOURCES = xine.c metronom.c configfile.c buffer.c monitor.c \
utils.c load_plugins.c video_decoder.c \
- audio_decoder.c video_out.c audio_out.c resample.c events.c
+ audio_decoder.c video_out.c audio_out.c resample.c events.c lrb.c
libxine_la_LIBADD = cpu_accel.lo \
$(THREAD_LIBS) \
$(DYNAMIC_LD_LIBS) \
@@ -24,7 +24,7 @@ libxine_la_LDFLAGS = \
include_HEADERS = buffer.h metronom.h configfile.h \
monitor.h cpu_accel.h attributes.h utils.h \
audio_out.h resample.h video_out.h xine_internal.h spu_decoder.h \
- events.h
+ events.h lrb.h
noinst_HEADERS = bswap.h
diff --git a/src/xine-engine/audio_decoder.c b/src/xine-engine/audio_decoder.c
index e2160b271..e829ec463 100644
--- a/src/xine-engine/audio_decoder.c
+++ b/src/xine-engine/audio_decoder.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_decoder.c,v 1.46 2001/10/07 03:53:11 heikos Exp $
+ * $Id: audio_decoder.c,v 1.47 2001/10/18 18:50:53 guenter Exp $
*
*
* functions that implement audio decoding
@@ -37,6 +37,8 @@
#include "utils.h"
#include "monitor.h"
+
+
void *audio_decoder_loop (void *this_gen) {
buf_element_t *buf;
@@ -53,8 +55,11 @@ void *audio_decoder_loop (void *this_gen) {
/* printf ("audio_loop: waiting for package...\n"); */
buf = this->audio_fifo->get (this->audio_fifo);
-
- /* printf ("audio_loop: got package pts = %d\n", buf->PTS); */
+
+ /*
+ printf ("audio_loop: got package pts = %d, type = %08x\n",
+ buf->PTS, buf->type);
+ */
if (buf->input_pos)
this->cur_input_pos = buf->input_pos;
@@ -62,18 +67,6 @@ void *audio_decoder_loop (void *this_gen) {
if (buf->input_time)
this->cur_input_time = buf->input_time;
- /*
- * Call update status callback function if
- * there is no video decoder initialized, like
- * in .mp3 playback.
- */
- /*
- if(this->cur_video_decoder_plugin == NULL) {
- if(this->status == XINE_PLAY)
- this->status_callback (this->status);
- }
- */
-
switch (buf->type) {
case BUF_CONTROL_START:
@@ -111,6 +104,10 @@ void *audio_decoder_loop (void *this_gen) {
pthread_mutex_unlock (&this->finished_lock);
+ /* future magic - coming soon
+ lrb_flush (this->audio_temp);
+ */
+
break;
case BUF_CONTROL_QUIT:
@@ -122,6 +119,7 @@ void *audio_decoder_loop (void *this_gen) {
break;
case BUF_VIDEO_FILL:
+ this->metronom->got_audio_still (this->metronom);
break;
case BUF_CONTROL_NOP:
@@ -144,6 +142,10 @@ void *audio_decoder_loop (void *this_gen) {
}
this->audio_channel = buf->decoder_info[0] & 0xff;
+ /* future magic - coming soon
+ lrb_feedback (this->audio_temp, this->audio_fifo);
+ */
+
break;
default:
@@ -159,8 +161,6 @@ void *audio_decoder_loop (void *this_gen) {
if ( (buf->type & 0xFF000000) == BUF_AUDIO_BASE ) {
- /* printf ("audio_loop: got an audio buffer, type %08x set %08X\n", buf->type, this->audio_channel); */
-
/* now, decode this buffer if it's the right track */
if (this->audio_channel == (buf->type & 0xFF) ) {
@@ -169,22 +169,26 @@ void *audio_decoder_loop (void *this_gen) {
decoder = this->audio_decoder_plugins [streamtype];
if (decoder) {
if (this->cur_audio_decoder_plugin != decoder) {
- if (this->cur_audio_decoder_plugin) {
+ if (this->cur_audio_decoder_plugin)
this->cur_audio_decoder_plugin->close (this->cur_audio_decoder_plugin);
- /* Since we are changing decoders, warn metronom of a possible
- * PTS discontinuity */
- this->metronom->expect_audio_discontinuity (this->metronom);
- this->metronom->expect_video_discontinuity (this->metronom);
- }
+
this->cur_audio_decoder_plugin = decoder;
this->cur_audio_decoder_plugin->init (this->cur_audio_decoder_plugin, this->audio_out);
+
printf ("audio_loop: using decoder >%s< \n",
decoder->get_identifier());
+
}
/* printf ("audio_loop: sending data to decoder\n"); */
decoder->decode_data (decoder, buf);
/* printf ("audio_loop: decoding is done\n"); */
}
+ } else {
+ /*
+ printf ("audio_decoder: wrong channel\n");
+ lrb_add (this->audio_temp, buf);
+ continue;
+ */
}
} else
printf ("audio_loop: unknown buffer type: %08x\n", buf->type);
@@ -212,6 +216,10 @@ void audio_decoder_init (xine_t *this) {
this->audio_fifo = fifo_buffer_new (1500, 8192);
+ /* future magic - coming soon
+ this->audio_temp = lrb_new (100, this->audio_fifo);
+ */
+
pthread_attr_init(&pth_attrs);
pthread_attr_getschedparam(&pth_attrs, &pth_params);
pth_params.sched_priority = sched_get_priority_min(SCHED_OTHER);
diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h
index 47b16b664..a959b9e5c 100644
--- a/src/xine-engine/buffer.h
+++ b/src/xine-engine/buffer.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: buffer.h,v 1.16 2001/10/10 10:54:48 jkeil Exp $
+ * $Id: buffer.h,v 1.17 2001/10/18 18:50:53 guenter Exp $
*
*
* contents:
@@ -41,6 +41,7 @@ extern "C" {
#include <stdio.h>
#include <pthread.h>
#include <inttypes.h>
+#include <sys/types.h>
/*
* buffer types
diff --git a/src/xine-engine/lrb.c b/src/xine-engine/lrb.c
new file mode 100644
index 000000000..dd71ef298
--- /dev/null
+++ b/src/xine-engine/lrb.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2000-2001 the xine project
+ *
+ * This file is part of xine, a unix video player.
+ *
+ * xine is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: lrb.c,v 1.1 2001/10/18 18:50:53 guenter Exp $
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include "lrb.h"
+#include "utils.h"
+
+lrb_t *lrb_new (int max_num_entries,
+ fifo_buffer_t *fifo) {
+
+ lrb_t *this;
+
+ this = xmalloc (sizeof (lrb_t));
+
+ this->max_num_entries = max_num_entries;
+ this->cur_num_entries = 0;
+ this->fifo = fifo;
+ this->newest = NULL;
+ this->oldest = NULL;
+
+ return this;
+}
+
+void lrb_drop (lrb_t *this) {
+
+ buf_element_t *buf = this->oldest;
+
+ assert (buf);
+
+ this->oldest = buf->next;
+
+ buf->free_buffer (buf);
+
+ this->cur_num_entries--;
+
+}
+
+void lrb_add (lrb_t *this, buf_element_t *buf) {
+
+ if (!this->newest) {
+
+ this->newest = buf;
+ this->oldest = buf;
+ buf->next = NULL;
+
+ this->cur_num_entries = 1;
+
+ } else {
+
+ if (this->cur_num_entries >= this->max_num_entries)
+ lrb_drop (this);
+
+ buf->next = NULL;
+ this->newest->next = buf;
+ this->newest = buf;
+ this->cur_num_entries++;
+ }
+
+ printf ("lrb: %d elements in buffer\n", this->cur_num_entries);
+
+}
+
+void lrb_feedback (lrb_t *this, fifo_buffer_t *fifo) {
+
+ pthread_mutex_lock (&fifo->mutex);
+
+ while (this->cur_num_entries) {
+
+ buf_element_t *buf = this->oldest;
+
+ buf->next = fifo->first;
+
+ fifo->first = buf;
+
+ if (!fifo->last)
+ fifo->last = buf;
+
+ fifo->fifo_size++;
+
+ pthread_cond_signal (&fifo->not_empty);
+
+ this->oldest = buf->next;
+
+ this->cur_num_entries--;
+
+ printf ("lrb: feedback\n");
+
+ }
+
+ if (!this->oldest)
+ this->newest = NULL;
+
+ pthread_mutex_unlock (&fifo->mutex);
+}
+
+void lrb_flush (lrb_t *this) {
+ while (this->cur_num_entries)
+ lrb_drop (this);
+}
diff --git a/src/xine-engine/lrb.h b/src/xine-engine/lrb.h
new file mode 100644
index 000000000..debe77a84
--- /dev/null
+++ b/src/xine-engine/lrb.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2001 the xine project
+ *
+ * This file is part of xine, a unix video player.
+ *
+ * xine is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: lrb.h,v 1.1 2001/10/18 18:50:53 guenter Exp $
+ *
+ * lrb : limited ring buffer
+ * used for temporal buffer, limited to n elements
+ *
+ */
+
+#ifndef HAVE_LRB_H
+#define HAVE_LRB_H
+
+#include "buffer.h"
+
+typedef struct {
+
+ int max_num_entries;
+ int cur_num_entries;
+
+ buf_element_t *newest, *oldest;
+ fifo_buffer_t *fifo;
+
+} lrb_t;
+
+
+lrb_t *lrb_new (int max_num_entries,
+ fifo_buffer_t *fifo) ;
+
+void lrb_drop (lrb_t *this) ;
+
+void lrb_add (lrb_t *this, buf_element_t *buf) ;
+
+void lrb_feedback (lrb_t *this, fifo_buffer_t *fifo) ;
+
+void lrb_flush (lrb_t *this) ;
+
+#endif
diff --git a/src/xine-engine/metronom.c b/src/xine-engine/metronom.c
index 4f93a736f..652c34457 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.29 2001/10/03 17:15:44 jkeil Exp $
+ * $Id: metronom.c,v 1.30 2001/10/18 18:50:53 guenter Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -264,8 +264,6 @@ static void metronom_video_stream_start (metronom_t *this) {
pthread_mutex_unlock (&this->lock);
- printf ("metronom: video stream start...done\n");
-
metronom_start_clock (this, 0);
}
@@ -529,13 +527,31 @@ static uint32_t metronom_got_video_frame (metronom_t *this, uint32_t pts) {
this->video_vpts += this->pts_per_frame + this->video_pts_delta;
this->num_video_vpts_guessed++ ;
- xprintf (METRONOM | VERBOSE, "metronom: video vpts for %10d : %10d\n", pts, vpts);
+#ifdef METRONOM_LOG
+ printf ("metronom: video vpts for %10d : %10d\n", pts, vpts);
+#endif
pthread_mutex_unlock (&this->lock);
return vpts + this->av_offset;
}
+static void metronom_got_audio_still (metronom_t *this) {
+
+ pthread_mutex_lock (&this->lock);
+
+ this->audio_vpts += this->pts_per_frame + this->video_pts_delta;
+ this->audio_wrap_offset = this->video_wrap_offset;
+ this->last_audio_pts = this->audio_vpts - this->audio_wrap_offset;
+ this->audio_stream_starting = 0;
+
+#ifdef METRONOM_LOG
+ printf ("metronom: got audio still, vpts = %d, wrap = %d\n",
+ this->audio_vpts, this->audio_wrap_offset);
+#endif
+
+ pthread_mutex_unlock (&this->lock);
+}
static uint32_t metronom_got_audio_samples (metronom_t *this, uint32_t pts, uint32_t nsamples) {
@@ -653,7 +669,9 @@ static uint32_t metronom_got_audio_samples (metronom_t *this, uint32_t pts, uint
this->audio_vpts += nsamples * (this->audio_pts_delta + this->pts_per_smpls) / AUDIO_SAMPLE_NUM;
this->num_audio_samples_guessed += nsamples;
- xprintf (METRONOM | VERBOSE, "metronom: audio vpts for %10d : %10d\n", pts, vpts);
+#ifdef METRONOM_LOG
+ printf ("metronom: audio vpts for %10d : %10d\n", pts, vpts);
+#endif
pthread_mutex_unlock (&this->lock);
@@ -766,6 +784,7 @@ metronom_t * metronom_init (int have_audio) {
this->register_scr = metronom_register_scr;
this->unregister_scr = metronom_unregister_scr;
this->set_speed = metronom_set_speed;
+ this->got_audio_still = metronom_got_audio_still;
this->scr_list = calloc(MAX_SCR_PROVIDERS, sizeof(void*));
this->register_scr(this, unixscr_init());
diff --git a/src/xine-engine/metronom.h b/src/xine-engine/metronom.h
index 4b436bdce..0452ab889 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.11 2001/09/12 22:18:47 guenter Exp $
+ * $Id: metronom.h,v 1.12 2001/10/18 18:50:53 guenter Exp $
*
* metronom: general pts => virtual calculation/assoc
*
@@ -102,6 +102,12 @@ struct metronom_s {
uint32_t (*got_audio_samples) (metronom_t *this, uint32_t pts, uint32_t nsamples);
+ /*
+ * inform metronom that there was a still image with no audio
+ */
+
+ void (*got_audio_still) (metronom_t *this);
+
/*
* called by SPU decoder whenever a packet is delivered to it
*
diff --git a/src/xine-engine/video_decoder.c b/src/xine-engine/video_decoder.c
index f958098e4..3e214bba1 100644
--- a/src/xine-engine/video_decoder.c
+++ b/src/xine-engine/video_decoder.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: video_decoder.c,v 1.55 2001/10/18 14:43:00 richwareham Exp $
+ * $Id: video_decoder.c,v 1.56 2001/10/18 18:50:53 guenter Exp $
*
*/
@@ -198,15 +198,8 @@ void *video_decoder_loop (void *this_gen) {
if (this->cur_video_decoder_plugin != decoder) {
- if (this->cur_video_decoder_plugin) {
+ if (this->cur_video_decoder_plugin)
this->cur_video_decoder_plugin->close (this->cur_video_decoder_plugin);
-
- /* Since we are changing decoders, warn metronom of a possible
- * PTS discontinuity */
-
- this->metronom->expect_video_discontinuity (this->metronom);
- this->metronom->expect_audio_discontinuity (this->metronom);
- }
this->cur_video_decoder_plugin = decoder;
this->cur_video_decoder_plugin->init (this->cur_video_decoder_plugin, this->video_out);
diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h
index 4376d4219..70e7e5d2e 100644
--- a/src/xine-engine/xine_internal.h
+++ b/src/xine-engine/xine_internal.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: xine_internal.h,v 1.49 2001/10/14 23:19:59 f1rmb Exp $
+ * $Id: xine_internal.h,v 1.50 2001/10/18 18:50:53 guenter Exp $
*
*/
@@ -42,6 +42,7 @@ extern "C" {
#include "metronom.h"
#include "spu_decoder.h"
#include "events.h"
+#include "lrb.h"
#ifdef XINE_COMPILE
#include "libspudec/spu_decoder_api.h"
#else
@@ -176,6 +177,7 @@ struct xine_s {
ao_instance_t *audio_out;
fifo_buffer_t *audio_fifo;
+ lrb_t *audio_temp;
pthread_t audio_thread;
audio_decoder_t *audio_decoder_plugins[DECODER_PLUGIN_MAX];
int num_audio_decoder_plugins;