summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Bartsch <guenter@users.sourceforge.net>2002-10-20 18:23:33 +0000
committerGuenter Bartsch <guenter@users.sourceforge.net>2002-10-20 18:23:33 +0000
commit54fadadea25e2f333ef03674518b644f15e6e8e4 (patch)
treed30a97a48e67020b5762202d06607177c84e6788
parentb0709abfd430c9b4b763f7346c7c52fef6263a2f (diff)
downloadxine-lib-54fadadea25e2f333ef03674518b644f15e6e8e4.tar.gz
xine-lib-54fadadea25e2f333ef03674518b644f15e6e8e4.tar.bz2
make avi demuxer send preview buffers, libmad uses them to extract stream/meta info
CVS patchset: 2886 CVS date: 2002/10/20 18:23:33
-rw-r--r--src/demuxers/demux_avi.c23
-rw-r--r--src/libmad/xine_decoder.c44
2 files changed, 53 insertions, 14 deletions
diff --git a/src/demuxers/demux_avi.c b/src/demuxers/demux_avi.c
index e7f833b1a..67d298bda 100644
--- a/src/demuxers/demux_avi.c
+++ b/src/demuxers/demux_avi.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: demux_avi.c,v 1.122 2002/10/20 13:50:41 guenter Exp $
+ * $Id: demux_avi.c,v 1.123 2002/10/20 18:23:33 guenter Exp $
*
* demultiplexer for avi streams
*
@@ -75,6 +75,8 @@
#define MAX_AUDIO_STREAMS 8
+#define NUM_PREVIEW_BUFFERS 10
+
/* The following variable indicates the kind of error */
typedef struct
@@ -1012,7 +1014,7 @@ static long AVI_read_video(demux_avi_t *this, avi_t *AVI, char *vidbuf,
}
-static int demux_avi_next (demux_avi_t *this) {
+static int demux_avi_next (demux_avi_t *this, int decoder_flags) {
int i;
buf_element_t *buf = NULL;
@@ -1074,6 +1076,7 @@ static int demux_avi_next (demux_avi_t *this) {
buf->pts = audio_pts;
buf->size = AVI_read_audio (this, audio, buf->mem, 2048, &buf->decoder_flags);
+ buf->decoder_flags |= decoder_flags;
if (buf->size<0) {
buf->free_buffer (buf);
@@ -1106,6 +1109,7 @@ static int demux_avi_next (demux_avi_t *this) {
buf->input_time = video_pts / 90000;
buf->input_pos = this->input->get_current_pos(this->input);
+ buf->decoder_flags |= decoder_flags;
if (buf->size<0) {
buf->free_buffer (buf);
@@ -1154,7 +1158,7 @@ static void *demux_avi_loop (void *this_gen) {
/* main demuxer loop */
while(this->status == DEMUX_OK) {
- if (!demux_avi_next(this)) {
+ if (!demux_avi_next (this, 0)) {
this->status = DEMUX_FINISHED;
}
@@ -1278,6 +1282,7 @@ static void demux_avi_send_headers (demux_plugin_t *this_gen) {
if (!this->thread_running) {
buf_element_t *buf;
+ int i;
xine_demux_control_start (this->stream);
@@ -1364,6 +1369,18 @@ static void demux_avi_send_headers (demux_plugin_t *this_gen) {
this->send_end_buffers = 1;
}
+
+ /*
+ * send preview buffers
+ */
+
+ AVI_seek_start (this->avi);
+
+ for (i=0; i<NUM_PREVIEW_BUFFERS; i++) {
+ if (!demux_avi_next(this, BUF_FLAG_PREVIEW))
+ break;
+ }
+
}
xine_demux_control_headers_done (this->stream);
diff --git a/src/libmad/xine_decoder.c b/src/libmad/xine_decoder.c
index cc766fdec..709ab5d0e 100644
--- a/src/libmad/xine_decoder.c
+++ b/src/libmad/xine_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: xine_decoder.c,v 1.30 2002/10/19 18:08:01 guenter Exp $
+ * $Id: xine_decoder.c,v 1.31 2002/10/20 18:23:33 guenter Exp $
*
* stuff needed to turn libmad into a xine decoder plugin
*/
@@ -45,13 +45,14 @@ typedef struct {
typedef struct mad_decoder_s {
audio_decoder_t audio_decoder;
+ xine_stream_t *xstream;
+
int64_t pts;
struct mad_synth synth;
struct mad_stream stream;
struct mad_frame frame;
- ao_instance_t *audio_out;
int output_sampling_rate;
int output_open;
int output_mode;
@@ -115,9 +116,6 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
printf ("libmad: decode data, decoder_info[0]: %d\n", buf->decoder_info[0]);
#endif
- if ( buf->decoder_flags & BUF_FLAG_PREVIEW )
- return;
-
if (buf->size>(INPUT_BUF_SIZE-this->bytes_in_buffer)) {
printf ("libmad: ALERT input buffer too small (%d bytes, %d avail)!\n",
buf->size, INPUT_BUF_SIZE-this->bytes_in_buffer);
@@ -174,12 +172,31 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
mode);
#endif
+ this->xstream->stream_info[XINE_STREAM_INFO_AUDIO_BITRATE] = this->frame.header.bitrate;
+ switch (this->frame.header.layer) {
+ case MAD_LAYER_I:
+ this->xstream->meta_info[XINE_META_INFO_AUDIOCODEC]
+ = strdup ("MPEG audio layer 1");
+ break;
+ case MAD_LAYER_II:
+ this->xstream->meta_info[XINE_META_INFO_AUDIOCODEC]
+ = strdup ("MPEG audio layer 2");
+ break;
+ case MAD_LAYER_III:
+ this->xstream->meta_info[XINE_META_INFO_AUDIOCODEC]
+ = strdup ("MPEG audio layer 3");
+ break;
+ default:
+ this->xstream->meta_info[XINE_META_INFO_AUDIOCODEC]
+ = strdup ("MPEG audio");
+ }
+
if (this->output_open) {
- this->audio_out->close (this->audio_out);
+ this->xstream->audio_out->close (this->xstream->audio_out);
this->output_open = 0;
}
if (!this->output_open) {
- this->output_open = this->audio_out->open(this->audio_out, 16,
+ this->output_open = this->xstream->audio_out->open(this->xstream->audio_out, 16,
this->frame.header.samplerate,
mode) ;
}
@@ -192,6 +209,10 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
mad_synth_frame (&this->synth, &this->frame);
+ if ( buf->decoder_flags & BUF_FLAG_PREVIEW )
+ return;
+
+
{
unsigned int nchannels, nsamples;
mad_fixed_t const *left_ch, *right_ch;
@@ -199,7 +220,7 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
audio_buffer_t *audio_buffer;
uint16_t *output;
- audio_buffer = this->audio_out->get_buffer (this->audio_out);
+ audio_buffer = this->xstream->audio_out->get_buffer (this->xstream->audio_out);
output = audio_buffer->mem;
nchannels = pcm->channels;
@@ -220,7 +241,7 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
audio_buffer->num_frames = pcm->length;
audio_buffer->vpts = buf->pts;
- this->audio_out->put_buffer (this->audio_out, audio_buffer);
+ this->xstream->audio_out->put_buffer (this->xstream->audio_out, audio_buffer);
buf->pts = 0;
@@ -243,7 +264,7 @@ static void mad_dispose (audio_decoder_t *this_gen) {
mad_stream_finish(&this->stream);
if (this->output_open) {
- this->audio_out->close (this->audio_out);
+ this->xstream->audio_out->close (this->xstream->audio_out);
this->output_open = 0;
}
@@ -260,10 +281,11 @@ static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stre
this->audio_decoder.reset = mad_reset;
this->audio_decoder.dispose = mad_dispose;
- this->audio_out = stream->audio_out;
this->output_open = 0;
this->bytes_in_buffer = 0;
+ this->xstream = stream;
+
mad_synth_init (&this->synth);
mad_stream_init (&this->stream);
mad_frame_init (&this->frame);