diff options
author | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2009-04-26 00:01:41 +0100 |
---|---|---|
committer | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2009-04-26 00:01:41 +0100 |
commit | 66c3a44b4feb04165e6849f54483b22611431482 (patch) | |
tree | 80f6326f4e93025f3fd5f9d75769cfbc44a2f7b3 /src | |
parent | b283b2b640024cff685dd019e9df992d31aebeab (diff) | |
parent | 8c3fd22df0ca058d6acd94772d79cd1550627b4d (diff) | |
download | xine-lib-66c3a44b4feb04165e6849f54483b22611431482.tar.gz xine-lib-66c3a44b4feb04165e6849f54483b22611431482.tar.bz2 |
Merge from 1.1.
--HG--
rename : src/xine-engine/buffer.h => include/xine/buffer.h
rename : src/libmad/xine_mad_decoder.c => src/audio_dec/xine_mad_decoder.c
Diffstat (limited to 'src')
-rw-r--r-- | src/audio_dec/xine_mad_decoder.c | 55 | ||||
-rw-r--r-- | src/demuxers/demux_mpgaudio.c | 50 | ||||
-rw-r--r-- | src/demuxers/demux_wav.c | 14 | ||||
-rw-r--r-- | src/xine-engine/load_plugins.c | 27 | ||||
-rw-r--r-- | src/xine-engine/metronom.c | 33 |
5 files changed, 136 insertions, 43 deletions
diff --git a/src/audio_dec/xine_mad_decoder.c b/src/audio_dec/xine_mad_decoder.c index 4bda91b40..9d66d4f5b 100644 --- a/src/audio_dec/xine_mad_decoder.c +++ b/src/audio_dec/xine_mad_decoder.c @@ -84,6 +84,9 @@ typedef struct mad_decoder_s { uint8_t buffer[INPUT_BUF_SIZE]; int bytes_in_buffer; int preview_mode; + int start_padding; + int end_padding; + int needs_more_data; } mad_decoder_t; @@ -98,6 +101,9 @@ static void mad_reset (audio_decoder_t *this_gen) { this->pts = 0; this->bytes_in_buffer = 0; this->preview_mode = 0; + this->start_padding = 0; + this->end_padding = 0; + this->needs_more_data = 0; mad_synth_init (&this->synth); mad_stream_init (&this->stream); @@ -187,6 +193,17 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { if (this->bytes_in_buffer < MAD_MIN_SIZE) return; + if (!this->needs_more_data) { + this->pts = buf->pts; + if (buf->decoder_flags & BUF_FLAG_AUDIO_PADDING) { + this->start_padding = buf->decoder_info[1]; + this->end_padding = buf->decoder_info[2]; + } else { + this->start_padding = 0; + this->end_padding = 0; + } + } + while (1) { if (mad_frame_decode (&this->frame, &this->stream) != 0) { @@ -204,6 +221,8 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { switch (this->stream.error) { case MAD_ERROR_BUFLEN: + /* libmad wants more data */ + this->needs_more_data = 1; return; default: @@ -284,7 +303,24 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { nsamples = pcm->length; left_ch = pcm->samples[0]; right_ch = pcm->samples[1]; - + + /* padding */ + if (this->start_padding || this->end_padding) { + /* check padding validity */ + if (nsamples < (this->start_padding + this->end_padding)) { + lprintf("invalid padding data"); + this->start_padding = 0; + this->end_padding = 0; + } + lprintf("nsamples=%d, start_padding=%d, end_padding=%d\n", + nsamples, this->start_padding, this->end_padding); + nsamples -= this->start_padding + this->end_padding; + left_ch += this->start_padding; + right_ch += this->start_padding; + } + audio_buffer->num_frames = nsamples; + audio_buffer->vpts = this->pts; + while (nsamples--) { /* output sample(s) in 16-bit signed little-endian PCM */ @@ -315,14 +351,21 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { this->xstream->audio_out->put_buffer (this->xstream->audio_out, audio_buffer, this->xstream); + this->pts = buf->pts; buf->pts = 0; - + if (buf->decoder_flags & BUF_FLAG_AUDIO_PADDING) { + this->start_padding = buf->decoder_info[1]; + this->end_padding = buf->decoder_info[2]; + buf->decoder_info[1] = 0; + buf->decoder_info[2] = 0; + } else { + this->start_padding = 0; + this->end_padding = 0; + } } - - lprintf ("decode worked\n"); + lprintf ("decode worked\n"); } - } - + } } } diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 4171b1de8..018f08eb9 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -65,11 +65,13 @@ /* Xing header stuff */ #define XING_TAG FOURCC_TAG('X', 'i', 'n', 'g') #define INFO_TAG FOURCC_TAG('I', 'n', 'f', 'o') +#define LAME_TAG FOURCC_TAG('L', 'A', 'M', 'E') #define XING_FRAMES_FLAG 0x0001 #define XING_BYTES_FLAG 0x0002 #define XING_TOC_FLAG 0x0004 #define XING_VBR_SCALE_FLAG 0x0008 #define XING_TOC_LENGTH 100 +#define LAME_HEADER_LENGTH 0xC0 /* Xing header stuff */ #define VBRI_TAG FOURCC_TAG('V', 'B', 'R', 'I') @@ -96,6 +98,10 @@ typedef struct { uint32_t stream_size; uint8_t toc[XING_TOC_LENGTH]; uint32_t vbr_scale; + + /* Lame extension */ + uint16_t start_delay; + uint16_t end_delay; } xing_header_t; /* Vbri Vbr Header struct */ @@ -402,9 +408,21 @@ static xing_header_t *XINE_MALLOC parse_xing_header(mpg_audio_frame_t *frame, xing->vbr_scale = -1; if (xing->flags & XING_VBR_SCALE_FLAG) { if (ptr >= (buf + bufsize - 4)) goto exit_error; - xing->vbr_scale = _X_BE_32(ptr); + xing->vbr_scale = _X_BE_32(ptr); ptr += 4; lprintf("vbr_scale: %d\n", xing->vbr_scale); } + + /* LAME extension */ + /* see http://gabriel.mp3-tech.org/mp3infotag.html */ + ptr -= 0x9C; /* move offset to match LAME header specs */ + if (ptr + LAME_HEADER_LENGTH >= (buf + bufsize - 4)) goto exit_error; + if (_X_BE_32(&ptr[0x9C]) == LAME_TAG) { + lprintf("Lame header found\n"); + xing->start_delay = (ptr[0xb1] << 4) | (ptr[0xb2] >> 4); + xing->end_delay = ((ptr[0xb2] & 0x0f) << 4) | ptr[0xb3]; + lprintf("start delay : %d samples\n", xing->start_delay); + lprintf("end delay : %d samples\n", xing->end_delay); + } } else { lprintf("Xing header not found\n"); } @@ -613,7 +631,22 @@ static int parse_frame_payload(demux_mpgaudio_t *this, buf->size = this->cur_frame.size; buf->type = BUF_AUDIO_MPEG; buf->decoder_info[0] = 1; - buf->decoder_flags = decoder_flags|BUF_FLAG_FRAME_END; + buf->decoder_flags = decoder_flags | BUF_FLAG_FRAME_END; + + /* send encoder padding */ + if (this->xing_header) { + if (frame_pos == this->mpg_frame_start) { + lprintf("sending a start padding of %d samples.\n", this->xing_header->start_delay); + buf->decoder_flags = buf->decoder_flags | BUF_FLAG_AUDIO_PADDING; + buf->decoder_info[1] = this->xing_header->start_delay; + buf->decoder_info[2] = 0; + } else if ((frame_pos + this->cur_frame.size) == this->mpg_frame_end) { + lprintf("sending a end padding of %d samples.\n", this->xing_header->end_delay); + buf->decoder_flags = buf->decoder_flags | BUF_FLAG_AUDIO_PADDING; + buf->decoder_info[1] = 0; + buf->decoder_info[2] = this->xing_header->end_delay; + } + } lprintf("send buffer: size=%d, pts=%"PRId64"\n", buf->size, pts); this->audio_fifo->put(this->audio_fifo, buf); @@ -768,9 +801,18 @@ static int demux_mpgaudio_send_chunk (demux_plugin_t *this_gen) { demux_mpgaudio_t *this = (demux_mpgaudio_t *) this_gen; - if (!demux_mpgaudio_next (this, 0, 0)) - this->status = DEMUX_FINISHED; + if (!demux_mpgaudio_next (this, 0, 0)) { + /* Hack: send 8 zero bytes to flush the libmad decoder */ + buf_element_t *buf; + buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); + buf->type = BUF_AUDIO_MPEG; + buf->decoder_flags = BUF_FLAG_FRAME_END; + buf->size = 8; + memset(buf->content, 0, buf->size); + this->audio_fifo->put(this->audio_fifo, buf); + this->status = DEMUX_FINISHED; + } return this->status; } diff --git a/src/demuxers/demux_wav.c b/src/demuxers/demux_wav.c index bfabfad38..39e96be26 100644 --- a/src/demuxers/demux_wav.c +++ b/src/demuxers/demux_wav.c @@ -66,6 +66,7 @@ typedef struct { off_t data_start; off_t data_size; + int send_newpts; int seek_flag; /* this is set when a seek just occurred */ } demux_wav_t; @@ -186,9 +187,9 @@ static int demux_wav_send_chunk(demux_plugin_t *this_gen) { current_pts *= 90000; current_pts /= this->wave->nAvgBytesPerSec; - if (this->seek_flag) { - _x_demux_control_newpts(this->stream, current_pts, BUF_FLAG_SEEK); - this->seek_flag = 0; + if (this->send_newpts) { + _x_demux_control_newpts(this->stream, current_pts, this->seek_flag); + this->send_newpts = this->seek_flag = 0; } while (remaining_sample_bytes) { @@ -289,10 +290,13 @@ static int demux_wav_seek (demux_plugin_t *this_gen, start_pos = (off_t) ( (double) start_pos / 65535 * this->data_size ); - this->seek_flag = 1; this->status = DEMUX_OK; - _x_demux_flush_engine (this->stream); + this->send_newpts = 1; + if (playing) { + this->seek_flag = 1; + _x_demux_flush_engine (this->stream); + } /* if input is non-seekable, do not proceed with the rest of this * seek function */ if (!INPUT_IS_SEEKABLE(this->input)) diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index ec8af4637..3f563dd62 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -1195,10 +1195,13 @@ static char *catalog_filename(xine_t *this, int createdir) { static void save_catalog (xine_t *this) { FILE *fp; char *const cachefile = catalog_filename(this, 1); + char *cachefile_new; if ( ! cachefile ) return; - if( (fp = fopen(cachefile,"w")) != NULL ) { + asprintf(&cachefile_new, "%s.new", cachefile); + + if( (fp = fopen(cachefile_new,"w")) != NULL ) { int i; fprintf(fp, "# this file is automatically created by xine, do not edit.\n\n"); @@ -1207,9 +1210,29 @@ static void save_catalog (xine_t *this) { for (i = 0; i < PLUGIN_TYPE_MAX; i++) { save_plugin_list (this, fp, this->plugin_catalog->plugin_lists[i]); } - fclose(fp); + if (fclose(fp)) + { + const char *err = strerror (errno); + xine_log (this, XINE_LOG_MSG, + _("failed to save catalogue cache: %s\n"), err); + goto do_unlink; + } + else if (rename (cachefile_new, cachefile)) + { + const char *err = strerror (errno); + xine_log (this, XINE_LOG_MSG, + _("failed to replace catalogue cache: %s\n"), err); + do_unlink: + if (unlink (cachefile_new) && errno != ENOENT) + { + err = strerror (errno); + xine_log (this, XINE_LOG_MSG, + _("failed to remove new catalogue cache: %s\n"), err); + } + } } free(cachefile); + free(cachefile_new); } /* diff --git a/src/xine-engine/metronom.c b/src/xine-engine/metronom.c index b120181b4..bd4c1e42f 100644 --- a/src/xine-engine/metronom.c +++ b/src/xine-engine/metronom.c @@ -304,6 +304,8 @@ static void metronom_handle_discontinuity (metronom_t *this, int type, /* video_vpts and audio_vpts adjustements */ cur_time = this->xine->clock->get_current_time(this->xine->clock); + xprintf(this->xine, XINE_VERBOSITY_DEBUG, + "current time : %" PRId64 "\n", cur_time); switch (type) { case DISC_STREAMSTART: @@ -320,33 +322,12 @@ static void metronom_handle_discontinuity (metronom_t *this, int type, case DISC_ABSOLUTE: case DISC_RELATIVE: - if (this->video_vpts < cur_time) { - /* still frame */ - if (this->audio_vpts > cur_time) { - /* still frame with audio */ - this->video_vpts = this->audio_vpts; - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video vpts adjusted to audio vpts %" PRId64 "\n", this->video_vpts); - } else { - /* still frame, no audio */ - this->video_vpts = this->prebuffer + cur_time; - this->audio_vpts = this->video_vpts; - this->audio_vpts_rmndr = 0; - this->force_video_jump = 1; - this->force_audio_jump = 1; - this->video_drift = 0; - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "vpts adjusted with prebuffer to %" PRId64 "\n", - this->video_vpts); - } + if (this->video_vpts < this->audio_vpts) { + this->video_vpts = this->audio_vpts; + xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video vpts adjusted to audio vpts %" PRId64 "\n", this->video_vpts); } else { - /* video */ - if (this->audio_vpts < cur_time) { - /* video, no sound */ - this->audio_vpts = this->video_vpts; - this->audio_vpts_rmndr = 0; - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "audio vpts adjusted to video vpts %" PRId64 "\n", this->video_vpts); - } else { - /* video + audio */ - } + this->audio_vpts = this->video_vpts; + xprintf(this->xine, XINE_VERBOSITY_DEBUG, "audio vpts adjusted to video vpts %" PRId64 "\n", this->video_vpts); } break; } |