From 0e0d536d4d4c3c354fdebd7ee8b1c70a2a9edc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 20:47:46 +0200 Subject: Move the flac plugins sources into the combined directory, like wavpack. --HG-- rename : src/libflac/decoder_flac.c => src/combined/decoder_flac.c rename : src/libflac/demux_flac.c => src/combined/demux_flac.c rename : src/libflac/demux_flac.h => src/combined/demux_flac.h --- src/Makefile.am | 1 - src/combined/Makefile.am | 11 +- src/combined/decoder_flac.c | 435 +++++++++++++++++++++++++ src/combined/demux_flac.c | 766 ++++++++++++++++++++++++++++++++++++++++++++ src/combined/demux_flac.h | 28 ++ src/libflac/Makefile.am | 14 - src/libflac/decoder_flac.c | 435 ------------------------- src/libflac/demux_flac.c | 766 -------------------------------------------- src/libflac/demux_flac.h | 28 -- 9 files changed, 1239 insertions(+), 1245 deletions(-) create mode 100644 src/combined/decoder_flac.c create mode 100644 src/combined/demux_flac.c create mode 100644 src/combined/demux_flac.h delete mode 100644 src/libflac/Makefile.am delete mode 100644 src/libflac/decoder_flac.c delete mode 100644 src/libflac/demux_flac.c delete mode 100644 src/libflac/demux_flac.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 0d5621593..df8e2d462 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,6 @@ SUBDIRS = \ libspeex \ libreal \ libfaad \ - libflac \ libmusepack \ post \ combined diff --git a/src/combined/Makefile.am b/src/combined/Makefile.am index 0d27f71c0..884fcf0cc 100644 --- a/src/combined/Makefile.am +++ b/src/combined/Makefile.am @@ -4,9 +4,18 @@ if HAVE_WAVPACK xineplug_wavpack = xineplug_wavpack.la endif -xineplug_LTLIBRARIES = $(xineplug_wavpack) +if HAVE_LIBFLAC +xineplug_flac = xineplug_flac.la +endif + +xineplug_LTLIBRARIES = $(xineplug_wavpack) $(xineplug_flac) xineplug_wavpack_la_SOURCES = demux_wavpack.c decoder_wavpack.c combined_wavpack.c combined_wavpack.h xineplug_wavpack_la_CFLAGS = $(VISIBILITY_FLAG) $(WAVPACK_CFLAGS) -I$(srcdir)/../demuxers xineplug_wavpack_la_LIBADD = $(XINE_LIB) $(WAVPACK_LIBS) xineplug_wavpack_la_LDFLAGS = $(xineplug_ldflags) + +xineplug_flac_la_SOURCES = demux_flac.c decoder_flac.c demux_flac.h +xineplug_flac_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBFLAC_CFLAGS) +xineplug_flac_la_LIBADD = $(XINE_LIB) $(LIBFLAC_LIBS) +xineplug_flac_la_LDFLAGS = $(xineplug_ldflags) diff --git a/src/combined/decoder_flac.c b/src/combined/decoder_flac.c new file mode 100644 index 000000000..9b77cc27d --- /dev/null +++ b/src/combined/decoder_flac.c @@ -0,0 +1,435 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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 + * + * John McCutchan 2003 + * FLAC Decoder (http://flac.sf.net) + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8 +#include +#define LEGACY_FLAC +#else +#undef LEGACY_FLAC +#endif + +#define LOG_MODULE "flac_decoder" +#define LOG_VERBOSE + +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" + +#include "demux_flac.h" + +typedef struct { + audio_decoder_class_t decoder_class; +} flac_class_t; + +typedef struct flac_decoder_s { + audio_decoder_t audio_decoder; + + int64_t pts; + + int output_sampling_rate; + int output_open; + int output_mode; + + xine_stream_t *stream; + + FLAC__StreamDecoder *flac_decoder; + + int sample_rate; + int bits_per_sample; + int channels; + + unsigned char *buf; + int buf_size; + int buf_pos; + int min_size; + +} flac_decoder_t; + +/* + * FLAC callback functions + */ + +static FLAC__StreamDecoderReadStatus +flac_read_callback (const FLAC__StreamDecoder *decoder, + FLAC__byte buffer[], + unsigned *bytes, + void *client_data) +{ + flac_decoder_t *this = (flac_decoder_t *)client_data; + int number_of_bytes_to_copy; + + lprintf("flac_read_callback: %d\n", *bytes); + + if (this->buf_pos > *bytes) + number_of_bytes_to_copy = *bytes; + else + number_of_bytes_to_copy = this->buf_pos; + + lprintf("number_of_bytes_to_copy: %d\n", number_of_bytes_to_copy); + + *bytes = number_of_bytes_to_copy; + + xine_fast_memcpy (buffer, this->buf, number_of_bytes_to_copy); + + this->buf_pos -= number_of_bytes_to_copy; + memmove(this->buf, &this->buf[number_of_bytes_to_copy], this->buf_pos ); + + if(number_of_bytes_to_copy) + return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; + else + return FLAC__STREAM_DECODER_READ_STATUS_ABORT; +} + +static FLAC__StreamDecoderWriteStatus +flac_write_callback (const FLAC__StreamDecoder *decoder, + const FLAC__Frame *frame, + const FLAC__int32 *const buffer[], + void *client_data) +{ + flac_decoder_t *this = (flac_decoder_t *)client_data; + audio_buffer_t *audio_buffer = NULL; + int samples_left = frame->header.blocksize; + int bytes_per_sample = (frame->header.bits_per_sample == 8)?1:2; + int buf_samples; + int8_t *data8; + int16_t *data16; + int i,j; + + lprintf("flac_write_callback\n"); + + while( samples_left ) { + + audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out); + + if( audio_buffer->mem_size < samples_left * frame->header.channels * bytes_per_sample ) + buf_samples = audio_buffer->mem_size / (frame->header.channels * bytes_per_sample); + else + buf_samples = samples_left; + + + if( frame->header.bits_per_sample == 8 ) { + data8 = (int8_t *)audio_buffer->mem; + + for( j=0; j < buf_samples; j++ ) + for( i=0; i < frame->header.channels; i++ ) + *data8++ = buffer[i][j]; + + } else { + + data16 = (int16_t *)audio_buffer->mem; + + for( j=0; j < buf_samples; j++ ) + for( i=0; i < frame->header.channels; i++ ) + *data16++ = buffer[i][j]; + } + + audio_buffer->num_frames = buf_samples; + audio_buffer->vpts = this->pts; + this->pts = 0; + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + + samples_left -= buf_samples; + } + return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; +} + +static void +flac_metadata_callback (const FLAC__StreamDecoder *decoder, + const FLAC__StreamMetadata *metadata, + void *client_data) +{ + /* flac_decoder_t *this = (flac_decoder_t *)client_data; */ + + lprintf("Metadata callback called!\n"); + +#ifdef LOG + if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { + printf("libflac: min_blocksize = %d\n", metadata->data.stream_info.min_blocksize); + printf("libflac: max_blocksize = %d\n", metadata->data.stream_info.max_blocksize); + printf("libflac: min_framesize = %d\n", metadata->data.stream_info.min_framesize); + printf("libflac: max_framesize = %d\n", metadata->data.stream_info.max_framesize); + /* does not work well: + this->min_size = 2 * metadata->data.stream_info.max_blocksize; */ + } +#endif + + return; +} + +static void +flac_error_callback (const FLAC__StreamDecoder *decoder, + FLAC__StreamDecoderErrorStatus status, + void *client_data) +{ + /* This will be called if there is an error in the flac stream */ + lprintf("flac_error_callback\n"); + +#ifdef LOG + if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) + printf("libflac: Decoder lost synchronization.\n"); + else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER) + printf("libflac: Decoder encounted a corrupted frame header.\n"); + else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH) + printf("libflac: Frame's data did not match the CRC in the footer.\n"); + else + printf("libflac: unknown error.\n"); +#endif + + return; +} + + +/* + * FLAC plugin decoder + */ + +static void +flac_reset (audio_decoder_t *this_gen) +{ + flac_decoder_t *this = (flac_decoder_t *) this_gen; + + this->buf_pos = 0; + + if( FLAC__stream_decoder_get_state(this->flac_decoder) != + FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) + FLAC__stream_decoder_flush (this->flac_decoder); +} + +static void +flac_discontinuity (audio_decoder_t *this_gen) +{ + flac_decoder_t *this = (flac_decoder_t *) this_gen; + + this->pts = 0; + + lprintf("Discontinuity!\n"); +} + +static void +flac_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) +{ + flac_decoder_t *this = (flac_decoder_t *) this_gen; + int ret = 1; + + /* We are getting the stream header, open up the audio + * device, and collect information about the stream + */ + if (buf->decoder_flags & BUF_FLAG_STDHEADER) + { + int mode = AO_CAP_MODE_MONO; + + this->sample_rate = buf->decoder_info[1]; + this->bits_per_sample = buf->decoder_info[2]; + this->channels = buf->decoder_info[3]; + + mode = _x_ao_channels2mode(this->channels); + + if (!this->output_open) + { + this->output_open = this->stream->audio_out->open ( + this->stream->audio_out, + this->stream, + this->bits_per_sample, + this->sample_rate, + mode); + + + } + this->buf_pos = 0; + } else if (this->output_open) + { + /* This isn't a header frame and we have opened the output device */ + + + /* What we have buffered so far, and what is coming in + * is larger than our buffer + */ + if (this->buf_pos + buf->size > this->buf_size) + { + this->buf_size += 2 * buf->size; + this->buf = realloc (this->buf, this->buf_size); + lprintf("reallocating buffer to %d\n", this->buf_size); + } + + xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size); + this->buf_pos += buf->size; + + if (buf->pts) + this->pts = buf->pts; + + /* We have enough to decode a frame */ + while( ret && this->buf_pos > this->min_size ) { + + FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(this->flac_decoder); + + if( state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) { + lprintf("process_until_end_of_metadata\n"); + ret = FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder); + } else if ( state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC || + state == FLAC__STREAM_DECODER_READ_FRAME ) { + lprintf("process_single\n"); + ret = FLAC__stream_decoder_process_single (this->flac_decoder); + } else { + lprintf("aborted.\n"); + FLAC__stream_decoder_flush (this->flac_decoder); + break; + } + } + } else + return; + + +} + +static void +flac_dispose (audio_decoder_t *this_gen) { + flac_decoder_t *this = (flac_decoder_t *) this_gen; + + FLAC__stream_decoder_finish (this->flac_decoder); + + FLAC__stream_decoder_delete (this->flac_decoder); + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + if (this->buf) + free(this->buf); + + free (this_gen); +} + +static audio_decoder_t * +open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + flac_decoder_t *this ; + + this = (flac_decoder_t *) xine_xmalloc (sizeof (flac_decoder_t)); + + this->audio_decoder.decode_data = flac_decode_data; + this->audio_decoder.reset = flac_reset; + this->audio_decoder.discontinuity = flac_discontinuity; + this->audio_decoder.dispose = flac_dispose; + this->stream = stream; + + this->output_open = 0; + this->buf = NULL; + this->buf_size = 0; + this->min_size = 65536; + this->pts = 0; + + this->flac_decoder = FLAC__stream_decoder_new(); + +#ifdef LEGACY_FLAC + FLAC__stream_decoder_set_read_callback (this->flac_decoder, + flac_read_callback); + FLAC__stream_decoder_set_write_callback (this->flac_decoder, + flac_write_callback); + FLAC__stream_decoder_set_metadata_callback (this->flac_decoder, + flac_metadata_callback); + FLAC__stream_decoder_set_error_callback (this->flac_decoder, + flac_error_callback); + + FLAC__stream_decoder_set_client_data (this->flac_decoder, this); + + if (FLAC__stream_decoder_init (this->flac_decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) { + free (this); + return NULL; + } +#else + if ( FLAC__stream_decoder_init_stream (this->flac_decoder, + flac_read_callback, + NULL, /* seek */ + NULL, /* tell */ + NULL, /* length */ + NULL, /* eof */ + flac_write_callback, + NULL, /* metadata */ + flac_error_callback, + this + ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { + free (this); + return NULL; + } +#endif + + return (audio_decoder_t *) this; +} + +/* + * flac plugin class + */ + +static char *get_identifier (audio_decoder_class_t *this) { + return "flacdec"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "flac audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void * +init_plugin (xine_t *xine, void *data) { + flac_class_t *this; + + this = (flac_class_t *) xine_xmalloc (sizeof (flac_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_FLAC, 0 + }; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_DEMUX, 26, "flac", XINE_VERSION_CODE, NULL, demux_flac_init_class }, + { PLUGIN_AUDIO_DECODER, 15, "flacdec", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/combined/demux_flac.c b/src/combined/demux_flac.c new file mode 100644 index 000000000..43ee17d5c --- /dev/null +++ b/src/combined/demux_flac.c @@ -0,0 +1,766 @@ +/* + * Copyright (C) 2000-2006 the xine project + * + * This file is part of xine, a free 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 + * + * + * John McCutchan + * FLAC demuxer (http://flac.sf.net) + * + * TODO: Skip id3v2 tags. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include + +#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8 +#include +#define LEGACY_FLAC +#else +#undef LEGACY_FLAC +#endif + +#define LOG_MODULE "demux_flac" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "xineutils.h" +#include "../demuxers/demux.h" + +#include "demux_flac.h" + +#ifndef LEGACY_FLAC +# define FLAC__SeekableStreamDecoder FLAC__StreamDecoder +#endif + +/* FLAC Demuxer plugin */ +typedef struct demux_flac_s { + demux_plugin_t demux_plugin; + + xine_stream_t *stream; + + fifo_buffer_t *audio_fifo; + fifo_buffer_t *video_fifo; + + input_plugin_t *input; + + int status; + + int seek_flag; + + off_t data_start; + off_t data_size; + + /* FLAC Stuff */ + FLAC__SeekableStreamDecoder *flac_decoder; + + uint64_t total_samples; + uint64_t bits_per_sample; + uint64_t channels; + uint64_t sample_rate; + uint64_t length_in_msec; +} demux_flac_t ; + + +/* FLAC Demuxer class */ +typedef struct demux_flac_class_s { + demux_class_t demux_class; + + xine_t *xine; + config_values_t *config; + +} demux_flac_class_t; + +/* FLAC Callbacks */ +static +#ifdef LEGACY_FLAC +FLAC__SeekableStreamDecoderReadStatus +#else +FLAC__StreamDecoderReadStatus +#endif +flac_read_callback (const FLAC__SeekableStreamDecoder *decoder, + FLAC__byte buffer[], + unsigned *bytes, + void *client_data) +{ + demux_flac_t *this = (demux_flac_t *)client_data; + input_plugin_t *input = this->input; + off_t offset = *bytes; + + lprintf("flac_read_callback\n"); + + /* This should only be called when flac is reading the metadata + * of the flac stream. + */ + + offset = input->read (input, buffer, offset); + + lprintf("Read %lld / %u bytes into buffer\n", offset, *bytes); + + /* This is the way to detect EOF with xine input plugins */ + if ( offset <= 0 && *bytes != 0 ) + { + *bytes = offset; + lprintf("Marking EOF\n"); + + this->status = DEMUX_FINISHED; +#ifdef LEGACY_FLAC + return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; +#else + return FLAC__STREAM_DECODER_READ_STATUS_ABORT; +#endif + } + else + { + *bytes = offset; + lprintf("Read was perfect\n"); + +#ifdef LEGACY_FLAC + return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; +#else + return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; +#endif + } +} + +static +#ifdef LEGACY_FLAC +FLAC__SeekableStreamDecoderSeekStatus +#else +FLAC__StreamDecoderSeekStatus +#endif +flac_seek_callback (const FLAC__SeekableStreamDecoder *decoder, + FLAC__uint64 absolute_byte_offset, + void *client_data) +{ + input_plugin_t *input = ((demux_flac_t *)client_data)->input; + off_t offset; + + lprintf("flac_seek_callback\n"); + + offset = input->seek (input, absolute_byte_offset, SEEK_SET); + + if (offset == -1) +#ifdef LEGACY_FLAC + return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; +#else + return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; +#endif + else +#ifdef LEGACY_FLAC + return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; +#else + return FLAC__STREAM_DECODER_SEEK_STATUS_OK; +#endif +} + +static +#ifdef LEGACY_FLAC +FLAC__SeekableStreamDecoderTellStatus +#else +FLAC__StreamDecoderTellStatus +#endif +flac_tell_callback (const FLAC__SeekableStreamDecoder *decoder, + FLAC__uint64 *absolute_byte_offset, + void *client_data) +{ + input_plugin_t *input = ((demux_flac_t *)client_data)->input; + off_t offset; + + lprintf("flac_tell_callback\n"); + + offset = input->get_current_pos (input); + + *absolute_byte_offset = offset; + +#ifdef LEGACY_FLAC + return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; +#else + return FLAC__STREAM_DECODER_TELL_STATUS_OK; +#endif +} + +static +#ifdef LEGACY_FLAC +FLAC__SeekableStreamDecoderLengthStatus +#else +FLAC__StreamDecoderLengthStatus +#endif +flac_length_callback (const FLAC__SeekableStreamDecoder *decoder, + FLAC__uint64 *stream_length, + void *client_data) +{ + input_plugin_t *input = ((demux_flac_t *)client_data)->input; + off_t offset; + + lprintf("flac_length_callback\n"); + + offset = input->get_length (input); + + /* FIXME, can flac handle -1 as offset ? */ +#ifdef LEGACY_FLAC + return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; +#else + return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; +#endif +} + +static FLAC__bool +flac_eof_callback (const FLAC__SeekableStreamDecoder *decoder, + void *client_data) +{ + demux_flac_t *this = (demux_flac_t *)client_data; + + lprintf("flac_eof_callback\n"); + + if (this->status == DEMUX_FINISHED) + { + lprintf("flac_eof_callback: True!\n"); + + return true; + } + else + { + lprintf("flac_eof_callback: False!\n"); + + return false; + } +} + +static FLAC__StreamDecoderWriteStatus +flac_write_callback (const FLAC__SeekableStreamDecoder *decoder, + const FLAC__Frame *frame, + const FLAC__int32 * const buffer[], + void *client_data) +{ + /* This should never be called, all we use flac for in this demuxer + * is seeking. We do the decoding in the decoder + */ + + lprintf("Error: Write callback was called!\n"); + + return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; +} + +static void +flac_metadata_callback (const FLAC__SeekableStreamDecoder *decoder, + const FLAC__StreamMetadata *metadata, + void *client_data) +{ + demux_flac_t *this = (demux_flac_t *)client_data; + + lprintf("IN: Metadata callback\n"); + + /* This should be called when we first look at a flac stream, + * We get information about the stream here. + */ + if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { + lprintf("Got METADATA!\n"); + + this->total_samples = metadata->data.stream_info.total_samples; + this->bits_per_sample = metadata->data.stream_info.bits_per_sample; + this->channels = metadata->data.stream_info.channels; + this->sample_rate = metadata->data.stream_info.sample_rate; + this->length_in_msec = (this->total_samples * 1000) / + this->sample_rate; + } + return; +} + +static void +flac_error_callback (const FLAC__SeekableStreamDecoder *decoder, + FLAC__StreamDecoderErrorStatus status, + void *client_data) +{ + demux_flac_t *this = (demux_flac_t *)client_data; + /* This will be called if there is an error when flac is seeking + * in the stream. + */ + + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_flac: flac_error_callback\n"); + + if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_flac: Decoder lost synchronization.\n"); + else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER) + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_flac: Decoder encounted a corrupted frame header.\n"); + else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH) + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_flac: Frame's data did not match the CRC in the footer.\n"); + else + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_flac: unknown error.\n"); + + this->status = DEMUX_FINISHED; + + return; +} + +/* FLAC Demuxer plugin */ +static int +demux_flac_send_chunk (demux_plugin_t *this_gen) { + demux_flac_t *this = (demux_flac_t *) this_gen; + buf_element_t *buf = NULL; + off_t current_file_pos, file_size = 0; + int64_t current_pts; + unsigned int remaining_sample_bytes = 0; + + remaining_sample_bytes = 2048; + + current_file_pos = this->input->get_current_pos (this->input) + - this->data_start; + if( (this->data_size - this->data_start) > 0 ) + file_size = (this->data_size - this->data_start); + + current_pts = current_file_pos; + current_pts *= this->length_in_msec * 90; + if( file_size ) + current_pts /= file_size; + + if (this->seek_flag) { +#ifdef USE_ESTIMATED_PTS + _x_demux_control_newpts (this->stream, current_pts, BUF_FLAG_SEEK); +#else + _x_demux_control_newpts (this->stream, 0, BUF_FLAG_SEEK); +#endif + this->seek_flag = 0; + } + + + while (remaining_sample_bytes) + { + if(!this->audio_fifo) { + this->status = DEMUX_FINISHED; + break; + } + + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = BUF_AUDIO_FLAC; + if( file_size ) + buf->extra_info->input_normpos = (int) ((double)current_file_pos * 65535 / file_size); + buf->extra_info->input_time = current_pts / 90; +#ifdef USE_ESTIMATED_PTS + buf->pts = current_pts; +#else + buf->pts = 0; +#endif + + if (remaining_sample_bytes > buf->max_size) + buf->size = buf->max_size; + else + buf->size = remaining_sample_bytes; + + remaining_sample_bytes -= buf->size; + + if (this->input->read (this->input,buf->content,buf->size)!=buf->size) { + lprintf("buf->size != input->read()\n"); + + buf->free_buffer (buf); + this->status = DEMUX_FINISHED; + break; + } + + /* + if (!remaining_sample_bytes) + { + buf->decoder_flags |= BUF_FLAG_FRAME_END; + }*/ + + this->audio_fifo->put (this->audio_fifo, buf); + } + + return this->status; +} + +static void +demux_flac_send_headers (demux_plugin_t *this_gen) { + demux_flac_t *this = (demux_flac_t *) this_gen; + + buf_element_t *buf; + + lprintf("demux_flac_send_headers\n"); + + this->video_fifo = this->stream->video_fifo; + this->audio_fifo = this->stream->audio_fifo; + + this->status = DEMUX_OK; + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 0); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, this->channels); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->sample_rate); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, this->bits_per_sample); + + _x_demux_control_start (this->stream); + + if (this->audio_fifo) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = BUF_AUDIO_FLAC; + buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; + buf->decoder_info[0] = 0; + buf->decoder_info[1] = this->sample_rate; + buf->decoder_info[2] = this->bits_per_sample; + buf->decoder_info[3] = this->channels; + buf->size = 0; + this->audio_fifo->put (this->audio_fifo, buf); + } +} + +static void +demux_flac_dispose (demux_plugin_t *this_gen) { + demux_flac_t *this = (demux_flac_t *) this_gen; + + lprintf("demux_flac_dispose\n"); + + if (this->flac_decoder) +#ifdef LEGACY_FLAC + FLAC__seekable_stream_decoder_delete (this->flac_decoder); +#else + FLAC__stream_decoder_delete (this->flac_decoder); +#endif + + free(this); + return; +} + +static int +demux_flac_get_status (demux_plugin_t *this_gen) { + demux_flac_t *this = (demux_flac_t *) this_gen; + + lprintf("demux_flac_get_status\n"); + + return this->status; +} + + +static int +demux_flac_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time, int playing) { + demux_flac_t *this = (demux_flac_t *) this_gen; + + lprintf("demux_flac_seek\n"); + + start_pos = (off_t) ( (double) start_pos / 65535 * + this->input->get_length (this->input) ); + + if (!start_pos && start_time) { + double distance = (double)start_time; + + if (this->length_in_msec != 0) + { + distance /= (double)this->length_in_msec; + } + start_pos = (uint64_t)(distance * (this->data_size - this->data_start)); + } + + if (start_pos || !start_time) { + + start_pos += this->data_start; + this->input->seek (this->input, start_pos, SEEK_SET); + lprintf ("Seek to position: %lld\n", start_pos); + + } else { + + double distance = (double)start_time; + uint64_t target_sample; + FLAC__bool s = false; + + if (this->length_in_msec != 0) + { + distance /= (double)this->length_in_msec; + } + target_sample = (uint64_t)(distance * this->total_samples); + +#ifdef LEGACY_FLAC + s = FLAC__seekable_stream_decoder_seek_absolute (this->flac_decoder, + target_sample); +#else + s = FLAC__stream_decoder_seek_absolute (this->flac_decoder, + target_sample); +#endif + + if (s) { + lprintf ("Seek to: %d successfull!\n", start_time); + } else + this->status = DEMUX_FINISHED; + } + + _x_demux_flush_engine (this->stream); + this->seek_flag = 1; + + return this->status; +} + +static int +demux_flac_get_stream_length (demux_plugin_t *this_gen) { + demux_flac_t *this = (demux_flac_t *) this_gen; + + lprintf("demux_flac_get_stream_length\n"); + + if (this->flac_decoder) + return this->length_in_msec; + else + return 0; +} + +static uint32_t +demux_flac_get_capabilities (demux_plugin_t *this_gen) { + lprintf("demux_flac_get_capabilities\n"); + + return DEMUX_CAP_NOCAP; +} + +static int +demux_flac_get_optional_data (demux_plugin_t *this_gen, void *data, int dtype) { + lprintf("demux_flac_get_optional_data\n"); + + return DEMUX_OPTIONAL_UNSUPPORTED; +} + +static demux_plugin_t * +open_plugin (demux_class_t *class_gen, + xine_stream_t *stream, + input_plugin_t *input) { + demux_flac_t *this; + + lprintf("open_plugin\n"); + + switch (stream->content_detection_method) { + case METHOD_BY_CONTENT: + { + uint8_t buf[MAX_PREVIEW_SIZE]; + int len; + + /* + * try to get a preview of the data + */ + len = input->get_optional_data (input, buf, INPUT_OPTIONAL_DATA_PREVIEW); + if (len == INPUT_OPTIONAL_UNSUPPORTED) { + + if (input->get_capabilities (input) & INPUT_CAP_SEEKABLE) { + + input->seek (input, 0, SEEK_SET); + if ( (len=input->read (input, buf, 1024)) <= 0) + return NULL; + input->seek (input, 0, SEEK_SET); + + } else + return NULL; + } + + /* FIXME: Skip id3v2 tag */ + /* Look for fLaC tag at the beginning of file */ + if ( (buf[0] != 'f') || (buf[1] != 'L') || + (buf[2] != 'a') || (buf[3] != 'C') ) + return NULL; + } + break; + case METHOD_BY_EXTENSION: { + char *ending, *mrl; + + mrl = input->get_mrl (input); + + ending = strrchr (mrl, '.'); + + if (!ending || (strlen (ending) < 5)) + return NULL; + + if (strncasecmp (ending, ".flac", 5)) + return NULL; + } + break; + case METHOD_EXPLICIT: + break; + default: + return NULL; + break; + } + + /* + * if we reach this point, the input has been accepted. + */ + + this = xine_xmalloc (sizeof (demux_flac_t)); + this->stream = stream; + this->input = input; + + this->demux_plugin.send_headers = demux_flac_send_headers; + this->demux_plugin.send_chunk = demux_flac_send_chunk; + this->demux_plugin.seek = demux_flac_seek; + this->demux_plugin.dispose = demux_flac_dispose; + this->demux_plugin.get_status = demux_flac_get_status; + this->demux_plugin.get_stream_length = demux_flac_get_stream_length; + this->demux_plugin.get_capabilities = demux_flac_get_capabilities; + this->demux_plugin.get_optional_data = demux_flac_get_optional_data; + this->demux_plugin.demux_class = class_gen; + + this->seek_flag = 0; + + + /* Get a new FLAC decoder and hook up callbacks */ +#ifdef LEGACY_FLAC + this->flac_decoder = FLAC__seekable_stream_decoder_new(); + lprintf("this->flac_decoder: %p\n", this->flac_decoder); + + FLAC__seekable_stream_decoder_set_md5_checking (this->flac_decoder, false); + FLAC__seekable_stream_decoder_set_read_callback (this->flac_decoder, + flac_read_callback); + FLAC__seekable_stream_decoder_set_seek_callback (this->flac_decoder, + flac_seek_callback); + FLAC__seekable_stream_decoder_set_tell_callback (this->flac_decoder, + flac_tell_callback); + FLAC__seekable_stream_decoder_set_length_callback (this->flac_decoder, + flac_length_callback); + FLAC__seekable_stream_decoder_set_eof_callback (this->flac_decoder, + flac_eof_callback); + FLAC__seekable_stream_decoder_set_metadata_callback (this->flac_decoder, + flac_metadata_callback); + FLAC__seekable_stream_decoder_set_write_callback (this->flac_decoder, + flac_write_callback); + FLAC__seekable_stream_decoder_set_error_callback (this->flac_decoder, + flac_error_callback); + FLAC__seekable_stream_decoder_set_client_data (this->flac_decoder, + this); + + FLAC__seekable_stream_decoder_init (this->flac_decoder); +#else + this->flac_decoder = FLAC__stream_decoder_new(); + lprintf("this->flac_decoder: %p\n", this->flac_decoder); + + if ( ! this->flac_decoder ) { + free(this); + return NULL; + } + + FLAC__stream_decoder_set_md5_checking (this->flac_decoder, false); + + if ( FLAC__stream_decoder_init_stream(this->flac_decoder, + flac_read_callback, + flac_seek_callback, + flac_tell_callback, + flac_length_callback, + flac_eof_callback, + flac_write_callback, + flac_metadata_callback, + flac_error_callback, + this + ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { +#ifdef LEGACY_FLAC + FLAC__seekable_stream_decoder_delete (this->flac_decoder); +#else + FLAC__stream_decoder_delete (this->flac_decoder); +#endif + free(this); + return NULL; + } +#endif + + /* Get some stream info */ + this->data_size = this->input->get_length (this->input); + this->data_start = this->input->get_current_pos (this->input); + + /* This will cause FLAC to give us the rest of the information on + * this flac stream + */ + this->status = DEMUX_OK; +#ifdef LEGACY_FLAC + FLAC__seekable_stream_decoder_process_until_end_of_metadata (this->flac_decoder); +#else + FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder); +#endif + + lprintf("Processed file until end of metadata: %s\n", + this->status == DEMUX_OK ? "success" : "failure"); + + if (this->status != DEMUX_OK) { +#ifdef LEGACY_FLAC + FLAC__seekable_stream_decoder_delete (this->flac_decoder); +#else + FLAC__stream_decoder_delete (this->flac_decoder); +#endif + free (this); + return NULL; + } + + return &this->demux_plugin; +} + + +/* FLAC Demuxer class */ + +static char * +get_description (demux_class_t *this_gen) { + return "FLAC demux plugin"; +} + +static char * +get_identifier (demux_class_t *this_gen) { + return "FLAC"; +} + +static char * +get_extensions (demux_class_t *this_gen) { + return "flac"; +} + +static char * +get_mimetypes (demux_class_t *this_gen) { + return "application/x-flac: flac: FLAC Audio;"; +} + +static void +class_dispose (demux_class_t *this_gen) { + demux_flac_class_t *this = (demux_flac_class_t *) this_gen; + + lprintf("class_dispose\n"); + + free (this); +} + +void * +demux_flac_init_class (xine_t *xine, void *data) { + + demux_flac_class_t *this; + + lprintf("demux_flac_init_class\n"); + + this = xine_xmalloc (sizeof (demux_flac_class_t)); + this->config = xine->config; + this->xine = xine; + + this->demux_class.open_plugin = open_plugin; + this->demux_class.get_description = get_description; + this->demux_class.get_identifier = get_identifier; + this->demux_class.get_mimetypes = get_mimetypes; + this->demux_class.get_extensions = get_extensions; + this->demux_class.dispose = class_dispose; + + return this; +} diff --git a/src/combined/demux_flac.h b/src/combined/demux_flac.h new file mode 100644 index 000000000..6086781d1 --- /dev/null +++ b/src/combined/demux_flac.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: demux_flac.h,v 1.2 2003/12/09 00:02:32 f1rmb Exp $ + */ + +#ifndef HAVE_DEMUX_FLAC_H +#define HAVE_DEMUX_FLAC_H + +void *demux_flac_init_class (xine_t *xine, void *data); + +#endif diff --git a/src/libflac/Makefile.am b/src/libflac/Makefile.am deleted file mode 100644 index 6449820bc..000000000 --- a/src/libflac/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -libdir = $(XINE_PLUGINDIR) - -if HAVE_LIBFLAC -lib_LTLIBRARIES = xineplug_flac.la -endif - -xineplug_flac_la_SOURCES = demux_flac.c decoder_flac.c -xineplug_flac_la_LIBADD = $(LIBFLAC_LIBS) $(XINE_LIB) -xineplug_flac_la_CFLAGS = $(LIBFLAC_CFLAGS) $(VISIBILITY_FLAG) -xineplug_flac_la_LDFLAGS = -avoid-version -module - -noinst_HEADERS = demux_flac.h diff --git a/src/libflac/decoder_flac.c b/src/libflac/decoder_flac.c deleted file mode 100644 index 9b77cc27d..000000000 --- a/src/libflac/decoder_flac.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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 - * - * John McCutchan 2003 - * FLAC Decoder (http://flac.sf.net) - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include - -#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8 -#include -#define LEGACY_FLAC -#else -#undef LEGACY_FLAC -#endif - -#define LOG_MODULE "flac_decoder" -#define LOG_VERBOSE - -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" - -#include "demux_flac.h" - -typedef struct { - audio_decoder_class_t decoder_class; -} flac_class_t; - -typedef struct flac_decoder_s { - audio_decoder_t audio_decoder; - - int64_t pts; - - int output_sampling_rate; - int output_open; - int output_mode; - - xine_stream_t *stream; - - FLAC__StreamDecoder *flac_decoder; - - int sample_rate; - int bits_per_sample; - int channels; - - unsigned char *buf; - int buf_size; - int buf_pos; - int min_size; - -} flac_decoder_t; - -/* - * FLAC callback functions - */ - -static FLAC__StreamDecoderReadStatus -flac_read_callback (const FLAC__StreamDecoder *decoder, - FLAC__byte buffer[], - unsigned *bytes, - void *client_data) -{ - flac_decoder_t *this = (flac_decoder_t *)client_data; - int number_of_bytes_to_copy; - - lprintf("flac_read_callback: %d\n", *bytes); - - if (this->buf_pos > *bytes) - number_of_bytes_to_copy = *bytes; - else - number_of_bytes_to_copy = this->buf_pos; - - lprintf("number_of_bytes_to_copy: %d\n", number_of_bytes_to_copy); - - *bytes = number_of_bytes_to_copy; - - xine_fast_memcpy (buffer, this->buf, number_of_bytes_to_copy); - - this->buf_pos -= number_of_bytes_to_copy; - memmove(this->buf, &this->buf[number_of_bytes_to_copy], this->buf_pos ); - - if(number_of_bytes_to_copy) - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; -} - -static FLAC__StreamDecoderWriteStatus -flac_write_callback (const FLAC__StreamDecoder *decoder, - const FLAC__Frame *frame, - const FLAC__int32 *const buffer[], - void *client_data) -{ - flac_decoder_t *this = (flac_decoder_t *)client_data; - audio_buffer_t *audio_buffer = NULL; - int samples_left = frame->header.blocksize; - int bytes_per_sample = (frame->header.bits_per_sample == 8)?1:2; - int buf_samples; - int8_t *data8; - int16_t *data16; - int i,j; - - lprintf("flac_write_callback\n"); - - while( samples_left ) { - - audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out); - - if( audio_buffer->mem_size < samples_left * frame->header.channels * bytes_per_sample ) - buf_samples = audio_buffer->mem_size / (frame->header.channels * bytes_per_sample); - else - buf_samples = samples_left; - - - if( frame->header.bits_per_sample == 8 ) { - data8 = (int8_t *)audio_buffer->mem; - - for( j=0; j < buf_samples; j++ ) - for( i=0; i < frame->header.channels; i++ ) - *data8++ = buffer[i][j]; - - } else { - - data16 = (int16_t *)audio_buffer->mem; - - for( j=0; j < buf_samples; j++ ) - for( i=0; i < frame->header.channels; i++ ) - *data16++ = buffer[i][j]; - } - - audio_buffer->num_frames = buf_samples; - audio_buffer->vpts = this->pts; - this->pts = 0; - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - samples_left -= buf_samples; - } - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -static void -flac_metadata_callback (const FLAC__StreamDecoder *decoder, - const FLAC__StreamMetadata *metadata, - void *client_data) -{ - /* flac_decoder_t *this = (flac_decoder_t *)client_data; */ - - lprintf("Metadata callback called!\n"); - -#ifdef LOG - if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - printf("libflac: min_blocksize = %d\n", metadata->data.stream_info.min_blocksize); - printf("libflac: max_blocksize = %d\n", metadata->data.stream_info.max_blocksize); - printf("libflac: min_framesize = %d\n", metadata->data.stream_info.min_framesize); - printf("libflac: max_framesize = %d\n", metadata->data.stream_info.max_framesize); - /* does not work well: - this->min_size = 2 * metadata->data.stream_info.max_blocksize; */ - } -#endif - - return; -} - -static void -flac_error_callback (const FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderErrorStatus status, - void *client_data) -{ - /* This will be called if there is an error in the flac stream */ - lprintf("flac_error_callback\n"); - -#ifdef LOG - if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) - printf("libflac: Decoder lost synchronization.\n"); - else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER) - printf("libflac: Decoder encounted a corrupted frame header.\n"); - else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH) - printf("libflac: Frame's data did not match the CRC in the footer.\n"); - else - printf("libflac: unknown error.\n"); -#endif - - return; -} - - -/* - * FLAC plugin decoder - */ - -static void -flac_reset (audio_decoder_t *this_gen) -{ - flac_decoder_t *this = (flac_decoder_t *) this_gen; - - this->buf_pos = 0; - - if( FLAC__stream_decoder_get_state(this->flac_decoder) != - FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) - FLAC__stream_decoder_flush (this->flac_decoder); -} - -static void -flac_discontinuity (audio_decoder_t *this_gen) -{ - flac_decoder_t *this = (flac_decoder_t *) this_gen; - - this->pts = 0; - - lprintf("Discontinuity!\n"); -} - -static void -flac_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) -{ - flac_decoder_t *this = (flac_decoder_t *) this_gen; - int ret = 1; - - /* We are getting the stream header, open up the audio - * device, and collect information about the stream - */ - if (buf->decoder_flags & BUF_FLAG_STDHEADER) - { - int mode = AO_CAP_MODE_MONO; - - this->sample_rate = buf->decoder_info[1]; - this->bits_per_sample = buf->decoder_info[2]; - this->channels = buf->decoder_info[3]; - - mode = _x_ao_channels2mode(this->channels); - - if (!this->output_open) - { - this->output_open = this->stream->audio_out->open ( - this->stream->audio_out, - this->stream, - this->bits_per_sample, - this->sample_rate, - mode); - - - } - this->buf_pos = 0; - } else if (this->output_open) - { - /* This isn't a header frame and we have opened the output device */ - - - /* What we have buffered so far, and what is coming in - * is larger than our buffer - */ - if (this->buf_pos + buf->size > this->buf_size) - { - this->buf_size += 2 * buf->size; - this->buf = realloc (this->buf, this->buf_size); - lprintf("reallocating buffer to %d\n", this->buf_size); - } - - xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size); - this->buf_pos += buf->size; - - if (buf->pts) - this->pts = buf->pts; - - /* We have enough to decode a frame */ - while( ret && this->buf_pos > this->min_size ) { - - FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(this->flac_decoder); - - if( state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) { - lprintf("process_until_end_of_metadata\n"); - ret = FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder); - } else if ( state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC || - state == FLAC__STREAM_DECODER_READ_FRAME ) { - lprintf("process_single\n"); - ret = FLAC__stream_decoder_process_single (this->flac_decoder); - } else { - lprintf("aborted.\n"); - FLAC__stream_decoder_flush (this->flac_decoder); - break; - } - } - } else - return; - - -} - -static void -flac_dispose (audio_decoder_t *this_gen) { - flac_decoder_t *this = (flac_decoder_t *) this_gen; - - FLAC__stream_decoder_finish (this->flac_decoder); - - FLAC__stream_decoder_delete (this->flac_decoder); - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - if (this->buf) - free(this->buf); - - free (this_gen); -} - -static audio_decoder_t * -open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - flac_decoder_t *this ; - - this = (flac_decoder_t *) xine_xmalloc (sizeof (flac_decoder_t)); - - this->audio_decoder.decode_data = flac_decode_data; - this->audio_decoder.reset = flac_reset; - this->audio_decoder.discontinuity = flac_discontinuity; - this->audio_decoder.dispose = flac_dispose; - this->stream = stream; - - this->output_open = 0; - this->buf = NULL; - this->buf_size = 0; - this->min_size = 65536; - this->pts = 0; - - this->flac_decoder = FLAC__stream_decoder_new(); - -#ifdef LEGACY_FLAC - FLAC__stream_decoder_set_read_callback (this->flac_decoder, - flac_read_callback); - FLAC__stream_decoder_set_write_callback (this->flac_decoder, - flac_write_callback); - FLAC__stream_decoder_set_metadata_callback (this->flac_decoder, - flac_metadata_callback); - FLAC__stream_decoder_set_error_callback (this->flac_decoder, - flac_error_callback); - - FLAC__stream_decoder_set_client_data (this->flac_decoder, this); - - if (FLAC__stream_decoder_init (this->flac_decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) { - free (this); - return NULL; - } -#else - if ( FLAC__stream_decoder_init_stream (this->flac_decoder, - flac_read_callback, - NULL, /* seek */ - NULL, /* tell */ - NULL, /* length */ - NULL, /* eof */ - flac_write_callback, - NULL, /* metadata */ - flac_error_callback, - this - ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { - free (this); - return NULL; - } -#endif - - return (audio_decoder_t *) this; -} - -/* - * flac plugin class - */ - -static char *get_identifier (audio_decoder_class_t *this) { - return "flacdec"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "flac audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void * -init_plugin (xine_t *xine, void *data) { - flac_class_t *this; - - this = (flac_class_t *) xine_xmalloc (sizeof (flac_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_FLAC, 0 - }; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_DEMUX, 26, "flac", XINE_VERSION_CODE, NULL, demux_flac_init_class }, - { PLUGIN_AUDIO_DECODER, 15, "flacdec", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libflac/demux_flac.c b/src/libflac/demux_flac.c deleted file mode 100644 index 43ee17d5c..000000000 --- a/src/libflac/demux_flac.c +++ /dev/null @@ -1,766 +0,0 @@ -/* - * Copyright (C) 2000-2006 the xine project - * - * This file is part of xine, a free 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 - * - * - * John McCutchan - * FLAC demuxer (http://flac.sf.net) - * - * TODO: Skip id3v2 tags. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include - -#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8 -#include -#define LEGACY_FLAC -#else -#undef LEGACY_FLAC -#endif - -#define LOG_MODULE "demux_flac" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "xineutils.h" -#include "../demuxers/demux.h" - -#include "demux_flac.h" - -#ifndef LEGACY_FLAC -# define FLAC__SeekableStreamDecoder FLAC__StreamDecoder -#endif - -/* FLAC Demuxer plugin */ -typedef struct demux_flac_s { - demux_plugin_t demux_plugin; - - xine_stream_t *stream; - - fifo_buffer_t *audio_fifo; - fifo_buffer_t *video_fifo; - - input_plugin_t *input; - - int status; - - int seek_flag; - - off_t data_start; - off_t data_size; - - /* FLAC Stuff */ - FLAC__SeekableStreamDecoder *flac_decoder; - - uint64_t total_samples; - uint64_t bits_per_sample; - uint64_t channels; - uint64_t sample_rate; - uint64_t length_in_msec; -} demux_flac_t ; - - -/* FLAC Demuxer class */ -typedef struct demux_flac_class_s { - demux_class_t demux_class; - - xine_t *xine; - config_values_t *config; - -} demux_flac_class_t; - -/* FLAC Callbacks */ -static -#ifdef LEGACY_FLAC -FLAC__SeekableStreamDecoderReadStatus -#else -FLAC__StreamDecoderReadStatus -#endif -flac_read_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__byte buffer[], - unsigned *bytes, - void *client_data) -{ - demux_flac_t *this = (demux_flac_t *)client_data; - input_plugin_t *input = this->input; - off_t offset = *bytes; - - lprintf("flac_read_callback\n"); - - /* This should only be called when flac is reading the metadata - * of the flac stream. - */ - - offset = input->read (input, buffer, offset); - - lprintf("Read %lld / %u bytes into buffer\n", offset, *bytes); - - /* This is the way to detect EOF with xine input plugins */ - if ( offset <= 0 && *bytes != 0 ) - { - *bytes = offset; - lprintf("Marking EOF\n"); - - this->status = DEMUX_FINISHED; -#ifdef LEGACY_FLAC - return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; -#else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; -#endif - } - else - { - *bytes = offset; - lprintf("Read was perfect\n"); - -#ifdef LEGACY_FLAC - return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; -#else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; -#endif - } -} - -static -#ifdef LEGACY_FLAC -FLAC__SeekableStreamDecoderSeekStatus -#else -FLAC__StreamDecoderSeekStatus -#endif -flac_seek_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 absolute_byte_offset, - void *client_data) -{ - input_plugin_t *input = ((demux_flac_t *)client_data)->input; - off_t offset; - - lprintf("flac_seek_callback\n"); - - offset = input->seek (input, absolute_byte_offset, SEEK_SET); - - if (offset == -1) -#ifdef LEGACY_FLAC - return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; -#else - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; -#endif - else -#ifdef LEGACY_FLAC - return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; -#else - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; -#endif -} - -static -#ifdef LEGACY_FLAC -FLAC__SeekableStreamDecoderTellStatus -#else -FLAC__StreamDecoderTellStatus -#endif -flac_tell_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 *absolute_byte_offset, - void *client_data) -{ - input_plugin_t *input = ((demux_flac_t *)client_data)->input; - off_t offset; - - lprintf("flac_tell_callback\n"); - - offset = input->get_current_pos (input); - - *absolute_byte_offset = offset; - -#ifdef LEGACY_FLAC - return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; -#else - return FLAC__STREAM_DECODER_TELL_STATUS_OK; -#endif -} - -static -#ifdef LEGACY_FLAC -FLAC__SeekableStreamDecoderLengthStatus -#else -FLAC__StreamDecoderLengthStatus -#endif -flac_length_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 *stream_length, - void *client_data) -{ - input_plugin_t *input = ((demux_flac_t *)client_data)->input; - off_t offset; - - lprintf("flac_length_callback\n"); - - offset = input->get_length (input); - - /* FIXME, can flac handle -1 as offset ? */ -#ifdef LEGACY_FLAC - return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; -#else - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; -#endif -} - -static FLAC__bool -flac_eof_callback (const FLAC__SeekableStreamDecoder *decoder, - void *client_data) -{ - demux_flac_t *this = (demux_flac_t *)client_data; - - lprintf("flac_eof_callback\n"); - - if (this->status == DEMUX_FINISHED) - { - lprintf("flac_eof_callback: True!\n"); - - return true; - } - else - { - lprintf("flac_eof_callback: False!\n"); - - return false; - } -} - -static FLAC__StreamDecoderWriteStatus -flac_write_callback (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__Frame *frame, - const FLAC__int32 * const buffer[], - void *client_data) -{ - /* This should never be called, all we use flac for in this demuxer - * is seeking. We do the decoding in the decoder - */ - - lprintf("Error: Write callback was called!\n"); - - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; -} - -static void -flac_metadata_callback (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__StreamMetadata *metadata, - void *client_data) -{ - demux_flac_t *this = (demux_flac_t *)client_data; - - lprintf("IN: Metadata callback\n"); - - /* This should be called when we first look at a flac stream, - * We get information about the stream here. - */ - if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - lprintf("Got METADATA!\n"); - - this->total_samples = metadata->data.stream_info.total_samples; - this->bits_per_sample = metadata->data.stream_info.bits_per_sample; - this->channels = metadata->data.stream_info.channels; - this->sample_rate = metadata->data.stream_info.sample_rate; - this->length_in_msec = (this->total_samples * 1000) / - this->sample_rate; - } - return; -} - -static void -flac_error_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__StreamDecoderErrorStatus status, - void *client_data) -{ - demux_flac_t *this = (demux_flac_t *)client_data; - /* This will be called if there is an error when flac is seeking - * in the stream. - */ - - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_flac: flac_error_callback\n"); - - if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_flac: Decoder lost synchronization.\n"); - else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_flac: Decoder encounted a corrupted frame header.\n"); - else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_flac: Frame's data did not match the CRC in the footer.\n"); - else - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_flac: unknown error.\n"); - - this->status = DEMUX_FINISHED; - - return; -} - -/* FLAC Demuxer plugin */ -static int -demux_flac_send_chunk (demux_plugin_t *this_gen) { - demux_flac_t *this = (demux_flac_t *) this_gen; - buf_element_t *buf = NULL; - off_t current_file_pos, file_size = 0; - int64_t current_pts; - unsigned int remaining_sample_bytes = 0; - - remaining_sample_bytes = 2048; - - current_file_pos = this->input->get_current_pos (this->input) - - this->data_start; - if( (this->data_size - this->data_start) > 0 ) - file_size = (this->data_size - this->data_start); - - current_pts = current_file_pos; - current_pts *= this->length_in_msec * 90; - if( file_size ) - current_pts /= file_size; - - if (this->seek_flag) { -#ifdef USE_ESTIMATED_PTS - _x_demux_control_newpts (this->stream, current_pts, BUF_FLAG_SEEK); -#else - _x_demux_control_newpts (this->stream, 0, BUF_FLAG_SEEK); -#endif - this->seek_flag = 0; - } - - - while (remaining_sample_bytes) - { - if(!this->audio_fifo) { - this->status = DEMUX_FINISHED; - break; - } - - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - buf->type = BUF_AUDIO_FLAC; - if( file_size ) - buf->extra_info->input_normpos = (int) ((double)current_file_pos * 65535 / file_size); - buf->extra_info->input_time = current_pts / 90; -#ifdef USE_ESTIMATED_PTS - buf->pts = current_pts; -#else - buf->pts = 0; -#endif - - if (remaining_sample_bytes > buf->max_size) - buf->size = buf->max_size; - else - buf->size = remaining_sample_bytes; - - remaining_sample_bytes -= buf->size; - - if (this->input->read (this->input,buf->content,buf->size)!=buf->size) { - lprintf("buf->size != input->read()\n"); - - buf->free_buffer (buf); - this->status = DEMUX_FINISHED; - break; - } - - /* - if (!remaining_sample_bytes) - { - buf->decoder_flags |= BUF_FLAG_FRAME_END; - }*/ - - this->audio_fifo->put (this->audio_fifo, buf); - } - - return this->status; -} - -static void -demux_flac_send_headers (demux_plugin_t *this_gen) { - demux_flac_t *this = (demux_flac_t *) this_gen; - - buf_element_t *buf; - - lprintf("demux_flac_send_headers\n"); - - this->video_fifo = this->stream->video_fifo; - this->audio_fifo = this->stream->audio_fifo; - - this->status = DEMUX_OK; - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 0); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, this->channels); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->sample_rate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, this->bits_per_sample); - - _x_demux_control_start (this->stream); - - if (this->audio_fifo) { - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - buf->type = BUF_AUDIO_FLAC; - buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; - buf->decoder_info[0] = 0; - buf->decoder_info[1] = this->sample_rate; - buf->decoder_info[2] = this->bits_per_sample; - buf->decoder_info[3] = this->channels; - buf->size = 0; - this->audio_fifo->put (this->audio_fifo, buf); - } -} - -static void -demux_flac_dispose (demux_plugin_t *this_gen) { - demux_flac_t *this = (demux_flac_t *) this_gen; - - lprintf("demux_flac_dispose\n"); - - if (this->flac_decoder) -#ifdef LEGACY_FLAC - FLAC__seekable_stream_decoder_delete (this->flac_decoder); -#else - FLAC__stream_decoder_delete (this->flac_decoder); -#endif - - free(this); - return; -} - -static int -demux_flac_get_status (demux_plugin_t *this_gen) { - demux_flac_t *this = (demux_flac_t *) this_gen; - - lprintf("demux_flac_get_status\n"); - - return this->status; -} - - -static int -demux_flac_seek (demux_plugin_t *this_gen, off_t start_pos, int start_time, int playing) { - demux_flac_t *this = (demux_flac_t *) this_gen; - - lprintf("demux_flac_seek\n"); - - start_pos = (off_t) ( (double) start_pos / 65535 * - this->input->get_length (this->input) ); - - if (!start_pos && start_time) { - double distance = (double)start_time; - - if (this->length_in_msec != 0) - { - distance /= (double)this->length_in_msec; - } - start_pos = (uint64_t)(distance * (this->data_size - this->data_start)); - } - - if (start_pos || !start_time) { - - start_pos += this->data_start; - this->input->seek (this->input, start_pos, SEEK_SET); - lprintf ("Seek to position: %lld\n", start_pos); - - } else { - - double distance = (double)start_time; - uint64_t target_sample; - FLAC__bool s = false; - - if (this->length_in_msec != 0) - { - distance /= (double)this->length_in_msec; - } - target_sample = (uint64_t)(distance * this->total_samples); - -#ifdef LEGACY_FLAC - s = FLAC__seekable_stream_decoder_seek_absolute (this->flac_decoder, - target_sample); -#else - s = FLAC__stream_decoder_seek_absolute (this->flac_decoder, - target_sample); -#endif - - if (s) { - lprintf ("Seek to: %d successfull!\n", start_time); - } else - this->status = DEMUX_FINISHED; - } - - _x_demux_flush_engine (this->stream); - this->seek_flag = 1; - - return this->status; -} - -static int -demux_flac_get_stream_length (demux_plugin_t *this_gen) { - demux_flac_t *this = (demux_flac_t *) this_gen; - - lprintf("demux_flac_get_stream_length\n"); - - if (this->flac_decoder) - return this->length_in_msec; - else - return 0; -} - -static uint32_t -demux_flac_get_capabilities (demux_plugin_t *this_gen) { - lprintf("demux_flac_get_capabilities\n"); - - return DEMUX_CAP_NOCAP; -} - -static int -demux_flac_get_optional_data (demux_plugin_t *this_gen, void *data, int dtype) { - lprintf("demux_flac_get_optional_data\n"); - - return DEMUX_OPTIONAL_UNSUPPORTED; -} - -static demux_plugin_t * -open_plugin (demux_class_t *class_gen, - xine_stream_t *stream, - input_plugin_t *input) { - demux_flac_t *this; - - lprintf("open_plugin\n"); - - switch (stream->content_detection_method) { - case METHOD_BY_CONTENT: - { - uint8_t buf[MAX_PREVIEW_SIZE]; - int len; - - /* - * try to get a preview of the data - */ - len = input->get_optional_data (input, buf, INPUT_OPTIONAL_DATA_PREVIEW); - if (len == INPUT_OPTIONAL_UNSUPPORTED) { - - if (input->get_capabilities (input) & INPUT_CAP_SEEKABLE) { - - input->seek (input, 0, SEEK_SET); - if ( (len=input->read (input, buf, 1024)) <= 0) - return NULL; - input->seek (input, 0, SEEK_SET); - - } else - return NULL; - } - - /* FIXME: Skip id3v2 tag */ - /* Look for fLaC tag at the beginning of file */ - if ( (buf[0] != 'f') || (buf[1] != 'L') || - (buf[2] != 'a') || (buf[3] != 'C') ) - return NULL; - } - break; - case METHOD_BY_EXTENSION: { - char *ending, *mrl; - - mrl = input->get_mrl (input); - - ending = strrchr (mrl, '.'); - - if (!ending || (strlen (ending) < 5)) - return NULL; - - if (strncasecmp (ending, ".flac", 5)) - return NULL; - } - break; - case METHOD_EXPLICIT: - break; - default: - return NULL; - break; - } - - /* - * if we reach this point, the input has been accepted. - */ - - this = xine_xmalloc (sizeof (demux_flac_t)); - this->stream = stream; - this->input = input; - - this->demux_plugin.send_headers = demux_flac_send_headers; - this->demux_plugin.send_chunk = demux_flac_send_chunk; - this->demux_plugin.seek = demux_flac_seek; - this->demux_plugin.dispose = demux_flac_dispose; - this->demux_plugin.get_status = demux_flac_get_status; - this->demux_plugin.get_stream_length = demux_flac_get_stream_length; - this->demux_plugin.get_capabilities = demux_flac_get_capabilities; - this->demux_plugin.get_optional_data = demux_flac_get_optional_data; - this->demux_plugin.demux_class = class_gen; - - this->seek_flag = 0; - - - /* Get a new FLAC decoder and hook up callbacks */ -#ifdef LEGACY_FLAC - this->flac_decoder = FLAC__seekable_stream_decoder_new(); - lprintf("this->flac_decoder: %p\n", this->flac_decoder); - - FLAC__seekable_stream_decoder_set_md5_checking (this->flac_decoder, false); - FLAC__seekable_stream_decoder_set_read_callback (this->flac_decoder, - flac_read_callback); - FLAC__seekable_stream_decoder_set_seek_callback (this->flac_decoder, - flac_seek_callback); - FLAC__seekable_stream_decoder_set_tell_callback (this->flac_decoder, - flac_tell_callback); - FLAC__seekable_stream_decoder_set_length_callback (this->flac_decoder, - flac_length_callback); - FLAC__seekable_stream_decoder_set_eof_callback (this->flac_decoder, - flac_eof_callback); - FLAC__seekable_stream_decoder_set_metadata_callback (this->flac_decoder, - flac_metadata_callback); - FLAC__seekable_stream_decoder_set_write_callback (this->flac_decoder, - flac_write_callback); - FLAC__seekable_stream_decoder_set_error_callback (this->flac_decoder, - flac_error_callback); - FLAC__seekable_stream_decoder_set_client_data (this->flac_decoder, - this); - - FLAC__seekable_stream_decoder_init (this->flac_decoder); -#else - this->flac_decoder = FLAC__stream_decoder_new(); - lprintf("this->flac_decoder: %p\n", this->flac_decoder); - - if ( ! this->flac_decoder ) { - free(this); - return NULL; - } - - FLAC__stream_decoder_set_md5_checking (this->flac_decoder, false); - - if ( FLAC__stream_decoder_init_stream(this->flac_decoder, - flac_read_callback, - flac_seek_callback, - flac_tell_callback, - flac_length_callback, - flac_eof_callback, - flac_write_callback, - flac_metadata_callback, - flac_error_callback, - this - ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { -#ifdef LEGACY_FLAC - FLAC__seekable_stream_decoder_delete (this->flac_decoder); -#else - FLAC__stream_decoder_delete (this->flac_decoder); -#endif - free(this); - return NULL; - } -#endif - - /* Get some stream info */ - this->data_size = this->input->get_length (this->input); - this->data_start = this->input->get_current_pos (this->input); - - /* This will cause FLAC to give us the rest of the information on - * this flac stream - */ - this->status = DEMUX_OK; -#ifdef LEGACY_FLAC - FLAC__seekable_stream_decoder_process_until_end_of_metadata (this->flac_decoder); -#else - FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder); -#endif - - lprintf("Processed file until end of metadata: %s\n", - this->status == DEMUX_OK ? "success" : "failure"); - - if (this->status != DEMUX_OK) { -#ifdef LEGACY_FLAC - FLAC__seekable_stream_decoder_delete (this->flac_decoder); -#else - FLAC__stream_decoder_delete (this->flac_decoder); -#endif - free (this); - return NULL; - } - - return &this->demux_plugin; -} - - -/* FLAC Demuxer class */ - -static char * -get_description (demux_class_t *this_gen) { - return "FLAC demux plugin"; -} - -static char * -get_identifier (demux_class_t *this_gen) { - return "FLAC"; -} - -static char * -get_extensions (demux_class_t *this_gen) { - return "flac"; -} - -static char * -get_mimetypes (demux_class_t *this_gen) { - return "application/x-flac: flac: FLAC Audio;"; -} - -static void -class_dispose (demux_class_t *this_gen) { - demux_flac_class_t *this = (demux_flac_class_t *) this_gen; - - lprintf("class_dispose\n"); - - free (this); -} - -void * -demux_flac_init_class (xine_t *xine, void *data) { - - demux_flac_class_t *this; - - lprintf("demux_flac_init_class\n"); - - this = xine_xmalloc (sizeof (demux_flac_class_t)); - this->config = xine->config; - this->xine = xine; - - this->demux_class.open_plugin = open_plugin; - this->demux_class.get_description = get_description; - this->demux_class.get_identifier = get_identifier; - this->demux_class.get_mimetypes = get_mimetypes; - this->demux_class.get_extensions = get_extensions; - this->demux_class.dispose = class_dispose; - - return this; -} diff --git a/src/libflac/demux_flac.h b/src/libflac/demux_flac.h deleted file mode 100644 index 6086781d1..000000000 --- a/src/libflac/demux_flac.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: demux_flac.h,v 1.2 2003/12/09 00:02:32 f1rmb Exp $ - */ - -#ifndef HAVE_DEMUX_FLAC_H -#define HAVE_DEMUX_FLAC_H - -void *demux_flac_init_class (xine_t *xine, void *data); - -#endif -- cgit v1.2.3 From 3b6ef82b64306c9d03341fe60e5ad641ad50809d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 21:07:48 +0200 Subject: Rename FFmpeg plugins' sources so that there are no conflicts with other source files. This way when you get a backtrace, video_decoder.c is never the FFmpeg one. --HG-- rename : src/libffmpeg/audio_decoder.c => src/libffmpeg/ff_audio_decoder.c rename : src/libffmpeg/dvaudio_decoder.c => src/libffmpeg/ff_dvaudio_decoder.c rename : src/libffmpeg/mpeg_parser.c => src/libffmpeg/ff_mpeg_parser.c rename : src/libffmpeg/mpeg_parser.h => src/libffmpeg/ff_mpeg_parser.h rename : src/libffmpeg/video_decoder.c => src/libffmpeg/ff_video_decoder.c rename : src/libffmpeg/xine_decoder.c => src/libffmpeg/ffmpeg_decoder.c rename : src/libffmpeg/xine_decoder.h => src/libffmpeg/ffmpeg_decoder.h rename : src/libffmpeg/xine_encoder.c => src/libffmpeg/ffmpeg_encoder.c --- src/libffmpeg/Makefile.am | 21 +- src/libffmpeg/audio_decoder.c | 554 ----------- src/libffmpeg/dvaudio_decoder.c | 433 --------- src/libffmpeg/ff_audio_decoder.c | 554 +++++++++++ src/libffmpeg/ff_dvaudio_decoder.c | 433 +++++++++ src/libffmpeg/ff_mpeg_parser.c | 323 +++++++ src/libffmpeg/ff_mpeg_parser.h | 83 ++ src/libffmpeg/ff_video_decoder.c | 1772 ++++++++++++++++++++++++++++++++++++ src/libffmpeg/ffmpeg_decoder.c | 329 +++++++ src/libffmpeg/ffmpeg_decoder.h | 56 ++ src/libffmpeg/ffmpeg_encoder.c | 334 +++++++ src/libffmpeg/mpeg_parser.c | 323 ------- src/libffmpeg/mpeg_parser.h | 83 -- src/libffmpeg/video_decoder.c | 1772 ------------------------------------ src/libffmpeg/xine_decoder.c | 329 ------- src/libffmpeg/xine_decoder.h | 56 -- src/libffmpeg/xine_encoder.c | 334 ------- 17 files changed, 3893 insertions(+), 3896 deletions(-) delete mode 100644 src/libffmpeg/audio_decoder.c delete mode 100644 src/libffmpeg/dvaudio_decoder.c create mode 100644 src/libffmpeg/ff_audio_decoder.c create mode 100644 src/libffmpeg/ff_dvaudio_decoder.c create mode 100644 src/libffmpeg/ff_mpeg_parser.c create mode 100644 src/libffmpeg/ff_mpeg_parser.h create mode 100644 src/libffmpeg/ff_video_decoder.c create mode 100644 src/libffmpeg/ffmpeg_decoder.c create mode 100644 src/libffmpeg/ffmpeg_decoder.h create mode 100644 src/libffmpeg/ffmpeg_encoder.c delete mode 100644 src/libffmpeg/mpeg_parser.c delete mode 100644 src/libffmpeg/mpeg_parser.h delete mode 100644 src/libffmpeg/video_decoder.c delete mode 100644 src/libffmpeg/xine_decoder.c delete mode 100644 src/libffmpeg/xine_decoder.h delete mode 100644 src/libffmpeg/xine_encoder.c (limited to 'src') diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am index 5f08ea20e..1efc77327 100644 --- a/src/libffmpeg/Makefile.am +++ b/src/libffmpeg/Makefile.am @@ -20,29 +20,26 @@ EXTRA_DIST = xine_encoder.c diff_to_ffmpeg_cvs.txt INTERNAL_DOCS = diff_to_ffmpeg_cvs.txt -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la +xineplug_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la if HAVE_DXR3 AM_CPPFLAGS = -I$(top_srcdir)/src/dxr3 $(X_CFLAGS) $(ff_cppflags) \ $(ZLIB_CPPFLAGS) -xineplug_decode_ff_la_SOURCES = xine_decoder.c audio_decoder.c video_decoder.c \ - xine_encoder.c mpeg_parser.c +xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ + ffmpeg_encoder.c ff_mpeg_parser.c ffmpeg_decoder.h \ + ff_mpeg_parser.h else AM_CPPFLAGS = $(ff_cppflags) $(ZLIB_CPPFLAGS) -xineplug_decode_ff_la_SOURCES = xine_decoder.c audio_decoder.c video_decoder.c \ - mpeg_parser.c +xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ + ff_mpeg_parser.c ffmpeg_decoder.h ff_mpeg_parser.h endif xineplug_decode_ff_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -xineplug_decode_ff_la_LDFLAGS = -avoid-version -module @IMPURE_TEXT_LDFLAGS@ +xineplug_decode_ff_la_LDFLAGS = $(xineplug_ldflags) $(IMPURE_TEXT_LDFLAGS) xineplug_decode_ff_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB) -lm $(ZLIB_LIBS) \ $(link_ffmpeg) $(PTHREAD_LIBS) xineplug_decode_dvaudio_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -xineplug_decode_dvaudio_la_LDFLAGS = -avoid-version -module -xineplug_decode_dvaudio_la_SOURCES = dvaudio_decoder.c +xineplug_decode_dvaudio_la_LDFLAGS = $(xineplug_ldflags) +xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB) - -noinst_HEADERS = xine_decoder.h mpeg_parser.h diff --git a/src/libffmpeg/audio_decoder.c b/src/libffmpeg/audio_decoder.c deleted file mode 100644 index 7ab1f56b4..000000000 --- a/src/libffmpeg/audio_decoder.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (C) 2001-2005 the xine project - * - * This file is part of xine, a free 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: audio_decoder.c,v 1.33 2007/01/28 18:38:33 miguelfreitas Exp $ - * - * xine audio decoder plugin using ffmpeg - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "ffmpeg_config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "ffmpeg_audio_dec" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" -#include "xine_decoder.h" - -#define AUDIOBUFSIZE (64 * 1024) - -typedef struct { - audio_decoder_class_t decoder_class; -} ff_audio_class_t; - -typedef struct ff_audio_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int output_open; - int audio_channels; - int audio_bits; - int audio_sample_rate; - - unsigned char *buf; - int bufsize; - int size; - - AVCodecContext *context; - AVCodec *codec; - - char *decode_buffer; - int decoder_ok; - -} ff_audio_decoder_t; - - -static const ff_codec_t ff_audio_lookup[] = { - {BUF_AUDIO_WMAV1, CODEC_ID_WMAV1, "MS Windows Media Audio 1 (ffmpeg)"}, - {BUF_AUDIO_WMAV2, CODEC_ID_WMAV2, "MS Windows Media Audio 2 (ffmpeg)"}, - {BUF_AUDIO_14_4, CODEC_ID_RA_144, "Real 14.4 (ffmpeg)"}, - {BUF_AUDIO_28_8, CODEC_ID_RA_288, "Real 28.8 (ffmpeg)"}, - {BUF_AUDIO_MPEG, CODEC_ID_MP3, "MP3 (ffmpeg)"}, - {BUF_AUDIO_MSADPCM, CODEC_ID_ADPCM_MS, "MS ADPCM (ffmpeg)"}, - {BUF_AUDIO_QTIMAADPCM, CODEC_ID_ADPCM_IMA_QT, "QT IMA ADPCM (ffmpeg)"}, - {BUF_AUDIO_MSIMAADPCM, CODEC_ID_ADPCM_IMA_WAV, "MS IMA ADPCM (ffmpeg)"}, - {BUF_AUDIO_DK3ADPCM, CODEC_ID_ADPCM_IMA_DK3, "Duck DK3 ADPCM (ffmpeg)"}, - {BUF_AUDIO_DK4ADPCM, CODEC_ID_ADPCM_IMA_DK4, "Duck DK4 ADPCM (ffmpeg)"}, - {BUF_AUDIO_VQA_IMA, CODEC_ID_ADPCM_IMA_WS, "Westwood Studios IMA (ffmpeg)"}, - {BUF_AUDIO_SMJPEG_IMA, CODEC_ID_ADPCM_IMA_SMJPEG, "SMJPEG IMA (ffmpeg)"}, - {BUF_AUDIO_XA_ADPCM, CODEC_ID_ADPCM_XA, "CD-ROM/XA ADPCM (ffmpeg)"}, - {BUF_AUDIO_4X_ADPCM, CODEC_ID_ADPCM_4XM, "4X ADPCM (ffmpeg)"}, - {BUF_AUDIO_EA_ADPCM, CODEC_ID_ADPCM_EA, "Electronic Arts ADPCM (ffmpeg)"}, - {BUF_AUDIO_MULAW, CODEC_ID_PCM_MULAW, "mu-law logarithmic PCM (ffmpeg)"}, - {BUF_AUDIO_ALAW, CODEC_ID_PCM_ALAW, "A-law logarithmic PCM (ffmpeg)"}, - {BUF_AUDIO_ROQ, CODEC_ID_ROQ_DPCM, "RoQ DPCM (ffmpeg)"}, - {BUF_AUDIO_INTERPLAY, CODEC_ID_INTERPLAY_DPCM, "Interplay DPCM (ffmpeg)"}, - {BUF_AUDIO_MAC3, CODEC_ID_MACE3, "MACE 3:1 (ffmpeg)"}, - {BUF_AUDIO_MAC6, CODEC_ID_MACE6, "MACE 6:1 (ffmpeg)"}, - {BUF_AUDIO_XAN_DPCM, CODEC_ID_XAN_DPCM, "Origin Xan DPCM (ffmpeg)"}, - {BUF_AUDIO_VMD, CODEC_ID_VMDAUDIO, "Sierra VMD Audio (ffmpeg)"}, - {BUF_AUDIO_FLAC, CODEC_ID_FLAC, "FLAC (ffmpeg)"}, - {BUF_AUDIO_SHORTEN, CODEC_ID_SHORTEN, "Shorten (ffmpeg)"}, - {BUF_AUDIO_ALAC, CODEC_ID_ALAC, "ALAC (ffmpeg)"}, - {BUF_AUDIO_QDESIGN2, CODEC_ID_QDM2, "QDesign (ffmpeg)"}, - {BUF_AUDIO_COOK, CODEC_ID_COOK, "RealAudio Cooker (ffmpeg)"}, - {BUF_AUDIO_TRUESPEECH, CODEC_ID_TRUESPEECH, "TrueSpeech (ffmpeg)"}, - {BUF_AUDIO_TTA, CODEC_ID_TTA, "True Audio Lossless (ffmpeg)"}, - {BUF_AUDIO_SMACKER, CODEC_ID_SMACKAUDIO, "Smacker (ffmpeg)"}, - {BUF_AUDIO_FLVADPCM, CODEC_ID_ADPCM_SWF, "Flash ADPCM (ffmpeg)"}, - {BUF_AUDIO_WAVPACK, CODEC_ID_WAVPACK, "WavPack (ffmpeg)"}, -}; - - - static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) { - if (size > this->bufsize) { - this->bufsize = size + size / 2; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } -} - -static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - int bytes_consumed; - int decode_buffer_size; - int offset; - int out; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_SPECIAL) ) { - - /* accumulate init data */ - ff_audio_ensure_buffer_size(this, this->size + buf->size); - memcpy(this->buf + this->size, buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - size_t i; - unsigned int codec_type; - xine_waveformatex *audio_header; - - codec_type = buf->type & 0xFFFF0000; - this->codec = NULL; - - for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) - if(ff_audio_lookup[i].type == codec_type) { - pthread_mutex_lock (&ffmpeg_lock); - this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); - pthread_mutex_unlock (&ffmpeg_lock); - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - ff_audio_lookup[i].name); - break; - } - - if (!this->codec) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), - codec_type); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - - this->context = avcodec_alloc_context(); - - if(buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->audio_sample_rate = buf->decoder_info[1]; - this->audio_channels = buf->decoder_info[3]; - - if(this->size) { - audio_header = (xine_waveformatex *)this->buf; - - this->context->block_align = audio_header->nBlockAlign; - this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; - - if(audio_header->cbSize > 0) { - this->context->extradata = xine_xmalloc(audio_header->cbSize); - this->context->extradata_size = audio_header->cbSize; - memcpy( this->context->extradata, - (uint8_t *)audio_header + sizeof(xine_waveformatex), - audio_header->cbSize ); - } - } - } else { - short *ptr; - - switch(codec_type) { - case BUF_AUDIO_14_4: - this->audio_sample_rate = 8000; - this->audio_channels = 1; - - this->context->block_align = 240; - break; - case BUF_AUDIO_28_8: - this->audio_sample_rate = BE_16(&this->buf[0x30]); - this->audio_channels = this->buf[0x37]; - /* this->audio_bits = buf->content[0x35] */ - - this->context->block_align = BE_16(&this->buf[0x2A]); - - this->context->extradata_size = 5*sizeof(short); - this->context->extradata = xine_xmalloc(this->context->extradata_size); - - ptr = (short *) this->context->extradata; - - ptr[0] = BE_16(&this->buf[0x2C]); /* subpacket size */ - ptr[1] = BE_16(&this->buf[0x28]); /* subpacket height */ - ptr[2] = BE_16(&this->buf[0x16]); /* subpacket flavour */ - ptr[3] = BE_32(&this->buf[0x18]); /* coded frame size */ - ptr[4] = 0; /* codec's data length */ - break; - default: - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type); - break; - } - } - - /* Current ffmpeg audio decoders always use 16 bits/sample - * buf->decoder_info[2] can't be used as it doesn't refer to the output - * bits/sample for some codecs (e.g. MS ADPCM) */ - this->audio_bits = 16; - - this->context->bits_per_sample = this->audio_bits; - this->context->sample_rate = this->audio_sample_rate; - this->context->channels = this->audio_channels; - this->context->codec_id = this->codec->id; - this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); - - this->size = 0; - - this->decode_buffer = xine_xmalloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); - - return; - } - } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) { - - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = xine_xmalloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); - - } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { - - if( !this->decoder_ok ) { - if ( ! this->context || ! this->codec ) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: trying to open null codec\n")); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - - pthread_mutex_lock (&ffmpeg_lock); - if (avcodec_open (this->context, this->codec) < 0) { - pthread_mutex_unlock (&ffmpeg_lock); - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: couldn't open decoder\n")); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - pthread_mutex_unlock (&ffmpeg_lock); - this->decoder_ok = 1; - } - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open(this->stream->audio_out, - this->stream, this->audio_bits, this->audio_sample_rate, - _x_ao_channels2mode(this->audio_channels)); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( buf->decoder_flags & BUF_FLAG_PREVIEW ) - return; - - ff_audio_ensure_buffer_size(this, this->size + buf->size); - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - - offset = 0; - while (this->size>0) { - decode_buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; - bytes_consumed = avcodec_decode_audio2 (this->context, - (int16_t *)this->decode_buffer, - &decode_buffer_size, - &this->buf[offset], - this->size); - - if (bytes_consumed<0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_audio_dec: error decompressing audio frame\n"); - this->size=0; - return; - } else if (bytes_consumed == 0 && decode_buffer_size == 0) { - if (offset) - memmove(this->buf, &this->buf[offset], this->size); - return; - } - - /* dispatch the decoded audio */ - out = 0; - while (out < decode_buffer_size) { - audio_buffer = - this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_audio_dec: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if ((decode_buffer_size - out) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = decode_buffer_size - out; - - /* fill up this buffer */ - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - - out += bytes_to_send; - } - - this->size -= bytes_consumed; - offset += bytes_consumed; - } - - /* reset internal accumulation buffer */ - this->size = 0; - } - } -} - -static void ff_audio_reset (audio_decoder_t *this_gen) { - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - - this->size = 0; - - /* try to reset the wma decoder */ - if( this->context && this->decoder_ok ) { - pthread_mutex_lock (&ffmpeg_lock); - avcodec_close (this->context); - avcodec_open (this->context, this->codec); - pthread_mutex_unlock (&ffmpeg_lock); - } -} - -static void ff_audio_discontinuity (audio_decoder_t *this_gen) { -} - -static void ff_audio_dispose (audio_decoder_t *this_gen) { - - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - - if( this->context && this->decoder_ok ) { - pthread_mutex_lock (&ffmpeg_lock); - avcodec_close (this->context); - pthread_mutex_unlock (&ffmpeg_lock); - } - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free(this->buf); - free(this->decode_buffer); - - if(this->context && this->context->extradata) - free(this->context->extradata); - - if(this->context) - free(this->context); - - free (this_gen); -} - -static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - ff_audio_decoder_t *this ; - - this = (ff_audio_decoder_t *) xine_xmalloc (sizeof (ff_audio_decoder_t)); - - this->audio_decoder.decode_data = ff_audio_decode_data; - this->audio_decoder.reset = ff_audio_reset; - this->audio_decoder.discontinuity = ff_audio_discontinuity; - this->audio_decoder.dispose = ff_audio_dispose; - - this->output_open = 0; - this->audio_channels = 0; - this->stream = stream; - this->buf = NULL; - this->size = 0; - this->bufsize = 0; - this->decoder_ok = 0; - - ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE); - - return &this->audio_decoder; -} - -static char *ff_audio_get_identifier (audio_decoder_class_t *this) { - return "ffmpeg audio"; -} - -static char *ff_audio_get_description (audio_decoder_class_t *this) { - return "ffmpeg based audio decoder plugin"; -} - -static void ff_audio_dispose_class (audio_decoder_class_t *this) { - free (this); -} - -void *init_audio_plugin (xine_t *xine, void *data) { - - ff_audio_class_t *this ; - - this = (ff_audio_class_t *) xine_xmalloc (sizeof (ff_audio_class_t)); - - this->decoder_class.open_plugin = ff_audio_open_plugin; - this->decoder_class.get_identifier = ff_audio_get_identifier; - this->decoder_class.get_description = ff_audio_get_description; - this->decoder_class.dispose = ff_audio_dispose_class; - - pthread_once( &once_control, init_once_routine ); - - return this; -} - -static uint32_t supported_audio_types[] = { - #ifdef CONFIG_WMAV1_DECODER - BUF_AUDIO_WMAV1, - #endif - #ifdef CONFIG_WMAV2_DECODER - BUF_AUDIO_WMAV2, - #endif - #ifdef CONFIG_RA_144_DECODER - BUF_AUDIO_14_4, - #endif - #ifdef CONFIG_RA_288_DECODER - BUF_AUDIO_28_8, - #endif - #ifdef CONFIG_MP3_DECODER - BUF_AUDIO_MPEG, - #endif - #ifdef CONFIG_ADPCM_MS_DECODER - BUF_AUDIO_MSADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_QT_DECODER - BUF_AUDIO_QTIMAADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_WAV_DECODER - BUF_AUDIO_MSIMAADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_DK3_DECODER - BUF_AUDIO_DK3ADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_DK4_DECODER - BUF_AUDIO_DK4ADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_WS_DECODER - BUF_AUDIO_VQA_IMA, - #endif - #ifdef CONFIG_ADPCM_IMA_SMJPEG_DECODER - BUF_AUDIO_SMJPEG_IMA, - #endif - #ifdef CONFIG_ADPCM_XA_DECODER - BUF_AUDIO_XA_ADPCM, - #endif - #ifdef CONFIG_ADPCM_4XM_DECODER - BUF_AUDIO_4X_ADPCM, - #endif - #ifdef CONFIG_ADPCM_EA_DECODER - BUF_AUDIO_EA_ADPCM, - #endif - #ifdef CONFIG_PCM_MULAW_DECODER - BUF_AUDIO_MULAW, - #endif - #ifdef CONFIG_PCM_ALAW_DECODER - BUF_AUDIO_ALAW, - #endif - #ifdef CONFIG_ROQ_DPCM_DECODER - BUF_AUDIO_ROQ, - #endif - #ifdef CONFIG_INTERPLAY_DPCM_DECODER - BUF_AUDIO_INTERPLAY, - #endif - #ifdef CONFIG_MACE3_DECODER - BUF_AUDIO_MAC3, - #endif - #ifdef CONFIG_MACE6_DECODER - BUF_AUDIO_MAC6, - #endif - #ifdef CONFIG_XAN_DPCM_DECODER - BUF_AUDIO_XAN_DPCM, - #endif - #ifdef CONFIG_VMDAUDIO_DECODER - BUF_AUDIO_VMD, - #endif - #ifdef CONFIG_FLAC_DECODER - BUF_AUDIO_FLAC, - #endif - #ifdef CONFIG_SHORTEN_DECODER - BUF_AUDIO_SHORTEN, - #endif - #ifdef CONFIG_ALAC_DECODER - BUF_AUDIO_ALAC, - #endif - #ifdef CONFIG_QDM2_DECODER - BUF_AUDIO_QDESIGN2, - #endif - #ifdef CONFIG_COOK_DECODER - BUF_AUDIO_COOK, - #endif - #ifdef CONFIG_TRUESPEECH_DECODER - BUF_AUDIO_TRUESPEECH, - #endif - #ifdef CONFIG_TTA_DECODER - BUF_AUDIO_TTA, - #endif - #ifdef CONFIG_SMACKAUDIO_DECODER - BUF_AUDIO_SMACKER, - #endif - #ifdef CONFIG_ADPCM_SWF_DECODER - BUF_AUDIO_FLVADPCM, - #endif - #ifdef CONFIG_WAVPACK_DECODER - BUF_AUDIO_WAVPACK, - #endif - - 0 -}; - -decoder_info_t dec_info_ffmpeg_audio = { - supported_audio_types, /* supported types */ - 6 /* priority */ -}; diff --git a/src/libffmpeg/dvaudio_decoder.c b/src/libffmpeg/dvaudio_decoder.c deleted file mode 100644 index 2c851bae1..000000000 --- a/src/libffmpeg/dvaudio_decoder.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2005 the xine project - * - * This file is part of xine, a free 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: dvaudio_decoder.c,v 1.12 2006/12/04 22:25:13 miguelfreitas Exp $ - * - * dv audio decoder based on patch by Dan Dennedy - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -#define LOG_MODULE "dvaudio" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "buffer.h" -#include "xineutils.h" - -#ifdef _MSC_VER -/* ffmpeg has own definitions of those types */ -# undef int8_t -# undef uint8_t -# undef int16_t -# undef uint16_t -# undef int32_t -# undef uint32_t -# undef int64_t -# undef uint64_t -#endif - -#ifdef HAVE_FFMPEG -# include -# include "libavcodec/dvdata.h" -#else -# include "libavcodec/avcodec.h" -# include "libavcodec/dvdata.h" -#endif - -#ifdef _MSC_VER -# undef malloc -# undef free -# undef realloc -#endif - -#define AUDIOBUFSIZE 128*1024 -#define MAXFRAMESIZE 131072 - - -typedef struct { - audio_decoder_class_t decoder_class; -} dvaudio_class_t; - -typedef struct dvaudio_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int output_open; - int audio_channels; - int audio_bits; - int audio_sample_rate; - - unsigned char *buf; - int bufsize; - int size; - - char *decode_buffer; - int decoder_ok; - -} dvaudio_decoder_t; - - -/* - * This is the dumbest implementation of all -- it simply looks at - * a fixed offset and if pack isn't there -- fails. We might want - * to have a fallback mechanism for complete search of missing packs. - */ -static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) -{ - int offs; - - switch (t) { - case dv_audio_source: - offs = (80*6 + 80*16*3 + 3); - break; - case dv_audio_control: - offs = (80*6 + 80*16*4 + 3); - break; - case dv_video_control: - offs = (80*5 + 48 + 5); - break; - default: - return NULL; - } - - return (frame[offs] == t ? &frame[offs] : NULL); -} - -static inline uint16_t dv_audio_12to16(uint16_t sample) -{ - uint16_t shift, result; - - sample = (sample < 0x800) ? sample : sample | 0xf000; - shift = (sample & 0xf00) >> 8; - - if (shift < 0x2 || shift > 0xd) { - result = sample; - } else if (shift < 0x8) { - shift--; - result = (sample - (256 * shift)) << shift; - } else { - shift = 0xe - shift; - result = ((sample + ((256 * shift) + 1)) << shift) - 1; - } - - return result; -} - -/* - * There's a couple of assumptions being made here: - * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. - * We can pass them upwards when ffmpeg will be ready to deal with them. - * 2. We don't do software emphasis. - * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples - * are converted into 16bit linear ones. - */ -static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2) -{ - int size, i, j, d, of, smpls, freq, quant, half_ch; - uint16_t lc, rc; - const DVprofile* sys; - const uint8_t* as_pack; - - as_pack = dv_extract_pack(frame, dv_audio_source); - if (!as_pack) /* No audio ? */ - return 0; - - sys = dv_frame_profile(frame); - smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ - freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ - quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ - - if (quant > 1) - return -1; /* Unsupported quantization */ - - size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ - half_ch = sys->difseg_size/2; - - /* for each DIF segment */ - for (i = 0; i < sys->difseg_size; i++) { - frame += 6 * 80; /* skip DIF segment header */ - if (quant == 1 && i == half_ch) { - if (!pcm2) - break; - else - pcm = pcm2; - } - - for (j = 0; j < 9; j++) { - for (d = 8; d < 80; d += 2) { - if (quant == 0) { /* 16bit quantization */ - of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; - if (of*2 >= size) - continue; - -#ifdef WORDS_BIGENDIAN - pcm[of*2] = frame[d]; - pcm[of*2+1] = frame[d+1]; -#else - pcm[of*2] = frame[d+1]; - pcm[of*2+1] = frame[d]; -#endif - if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) - pcm[of*2+1] = 0; - } else { /* 12bit quantization */ - lc = ((uint16_t)frame[d] << 4) | - ((uint16_t)frame[d+2] >> 4); - rc = ((uint16_t)frame[d+1] << 4) | - ((uint16_t)frame[d+2] & 0x0f); - lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); - rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); - - of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; - if (of*2 >= size) - continue; - -#ifdef WORDS_BIGENDIAN - pcm[of*2] = lc >> 8; - pcm[of*2+1] = lc & 0xff; -#else - pcm[of*2] = lc & 0xff; - pcm[of*2+1] = lc >> 8; -#endif - of = sys->audio_shuffle[i%half_ch+half_ch][j] + - (d - 8)/3 * sys->audio_stride; -#ifdef WORDS_BIGENDIAN - pcm[of*2] = rc >> 8; - pcm[of*2+1] = rc & 0xff; -#else - pcm[of*2] = rc & 0xff; - pcm[of*2+1] = rc >> 8; -#endif - ++d; - } - } - - frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ - } - } - - return size; -} - -static void dvaudio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - int bytes_consumed; - int decode_buffer_size; - int offset; - int out; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - this->decode_buffer = xine_xmalloc(MAXFRAMESIZE); - - this->audio_sample_rate = buf->decoder_info[1]; - this->audio_bits = buf->decoder_info[2]; - this->audio_channels = buf->decoder_info[3]; - - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DV Audio"); - - this->decoder_ok = 1; - - return; - } - - if (this->decoder_ok && !(buf->decoder_flags & (BUF_FLAG_HEADER|BUF_FLAG_SPECIAL))) { - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open(this->stream->audio_out, - this->stream, this->audio_bits, this->audio_sample_rate, - _x_ao_channels2mode(this->audio_channels)); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("dvaudio: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - - offset = 0; - while (this->size>0) { - decode_buffer_size = dv_extract_audio(&this->buf[offset], this->decode_buffer, NULL); - - if (decode_buffer_size > -1) - bytes_consumed = dv_frame_profile(&this->buf[offset])->frame_size; - else - bytes_consumed = decode_buffer_size; - - /* dispatch the decoded audio */ - out = 0; - while (out < decode_buffer_size) { - audio_buffer = - this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "dvaudio: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if ((decode_buffer_size - out) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = decode_buffer_size - out; - - /* fill up this buffer */ - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - - out += bytes_to_send; - } - - this->size -= bytes_consumed; - offset += bytes_consumed; - } - - /* reset internal accumulation buffer */ - this->size = 0; - } - } -} - -static void dvaudio_reset (audio_decoder_t *this_gen) { - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - - this->size = 0; -} - -static void dvaudio_discontinuity (audio_decoder_t *this_gen) { -} - -static void dvaudio_dispose (audio_decoder_t *this_gen) { - - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free(this->buf); - free(this->decode_buffer); - - free (this_gen); -} - -static audio_decoder_t *dvaudio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - dvaudio_decoder_t *this ; - - this = (dvaudio_decoder_t *) xine_xmalloc (sizeof (dvaudio_decoder_t)); - - this->audio_decoder.decode_data = dvaudio_decode_data; - this->audio_decoder.reset = dvaudio_reset; - this->audio_decoder.discontinuity = dvaudio_discontinuity; - this->audio_decoder.dispose = dvaudio_dispose; - - this->output_open = 0; - this->audio_channels = 0; - this->stream = stream; - this->buf = NULL; - this->size = 0; - this->decoder_ok = 0; - - return &this->audio_decoder; -} - -static char *dvaudio_get_identifier (audio_decoder_class_t *this) { - return "dv audio"; -} - -static char *dvaudio_get_description (audio_decoder_class_t *this) { - return "dv audio decoder plugin"; -} - -static void dvaudio_dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_dvaudio_plugin (xine_t *xine, void *data) { - - dvaudio_class_t *this ; - - this = (dvaudio_class_t *) xine_xmalloc (sizeof (dvaudio_class_t)); - - this->decoder_class.open_plugin = dvaudio_open_plugin; - this->decoder_class.get_identifier = dvaudio_get_identifier; - this->decoder_class.get_description = dvaudio_get_description; - this->decoder_class.dispose = dvaudio_dispose_class; - - return this; -} - -static uint32_t supported_audio_types[] = { - BUF_AUDIO_DV, - 0 -}; - -static const decoder_info_t dec_info_dvaudio = { - supported_audio_types, /* supported types */ - 5 /* priority */ -}; - -/* - * exported plugin catalog entry - */ - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "dvaudio", XINE_VERSION_CODE, &dec_info_dvaudio, init_dvaudio_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libffmpeg/ff_audio_decoder.c b/src/libffmpeg/ff_audio_decoder.c new file mode 100644 index 000000000..e0d6e5cab --- /dev/null +++ b/src/libffmpeg/ff_audio_decoder.c @@ -0,0 +1,554 @@ +/* + * Copyright (C) 2001-2005 the xine project + * + * This file is part of xine, a free 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: audio_decoder.c,v 1.33 2007/01/28 18:38:33 miguelfreitas Exp $ + * + * xine audio decoder plugin using ffmpeg + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "ffmpeg_config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "ffmpeg_audio_dec" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "buffer.h" +#include "xineutils.h" +#include "bswap.h" +#include "ffmpeg_decoder.h" + +#define AUDIOBUFSIZE (64 * 1024) + +typedef struct { + audio_decoder_class_t decoder_class; +} ff_audio_class_t; + +typedef struct ff_audio_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + int output_open; + int audio_channels; + int audio_bits; + int audio_sample_rate; + + unsigned char *buf; + int bufsize; + int size; + + AVCodecContext *context; + AVCodec *codec; + + char *decode_buffer; + int decoder_ok; + +} ff_audio_decoder_t; + + +static const ff_codec_t ff_audio_lookup[] = { + {BUF_AUDIO_WMAV1, CODEC_ID_WMAV1, "MS Windows Media Audio 1 (ffmpeg)"}, + {BUF_AUDIO_WMAV2, CODEC_ID_WMAV2, "MS Windows Media Audio 2 (ffmpeg)"}, + {BUF_AUDIO_14_4, CODEC_ID_RA_144, "Real 14.4 (ffmpeg)"}, + {BUF_AUDIO_28_8, CODEC_ID_RA_288, "Real 28.8 (ffmpeg)"}, + {BUF_AUDIO_MPEG, CODEC_ID_MP3, "MP3 (ffmpeg)"}, + {BUF_AUDIO_MSADPCM, CODEC_ID_ADPCM_MS, "MS ADPCM (ffmpeg)"}, + {BUF_AUDIO_QTIMAADPCM, CODEC_ID_ADPCM_IMA_QT, "QT IMA ADPCM (ffmpeg)"}, + {BUF_AUDIO_MSIMAADPCM, CODEC_ID_ADPCM_IMA_WAV, "MS IMA ADPCM (ffmpeg)"}, + {BUF_AUDIO_DK3ADPCM, CODEC_ID_ADPCM_IMA_DK3, "Duck DK3 ADPCM (ffmpeg)"}, + {BUF_AUDIO_DK4ADPCM, CODEC_ID_ADPCM_IMA_DK4, "Duck DK4 ADPCM (ffmpeg)"}, + {BUF_AUDIO_VQA_IMA, CODEC_ID_ADPCM_IMA_WS, "Westwood Studios IMA (ffmpeg)"}, + {BUF_AUDIO_SMJPEG_IMA, CODEC_ID_ADPCM_IMA_SMJPEG, "SMJPEG IMA (ffmpeg)"}, + {BUF_AUDIO_XA_ADPCM, CODEC_ID_ADPCM_XA, "CD-ROM/XA ADPCM (ffmpeg)"}, + {BUF_AUDIO_4X_ADPCM, CODEC_ID_ADPCM_4XM, "4X ADPCM (ffmpeg)"}, + {BUF_AUDIO_EA_ADPCM, CODEC_ID_ADPCM_EA, "Electronic Arts ADPCM (ffmpeg)"}, + {BUF_AUDIO_MULAW, CODEC_ID_PCM_MULAW, "mu-law logarithmic PCM (ffmpeg)"}, + {BUF_AUDIO_ALAW, CODEC_ID_PCM_ALAW, "A-law logarithmic PCM (ffmpeg)"}, + {BUF_AUDIO_ROQ, CODEC_ID_ROQ_DPCM, "RoQ DPCM (ffmpeg)"}, + {BUF_AUDIO_INTERPLAY, CODEC_ID_INTERPLAY_DPCM, "Interplay DPCM (ffmpeg)"}, + {BUF_AUDIO_MAC3, CODEC_ID_MACE3, "MACE 3:1 (ffmpeg)"}, + {BUF_AUDIO_MAC6, CODEC_ID_MACE6, "MACE 6:1 (ffmpeg)"}, + {BUF_AUDIO_XAN_DPCM, CODEC_ID_XAN_DPCM, "Origin Xan DPCM (ffmpeg)"}, + {BUF_AUDIO_VMD, CODEC_ID_VMDAUDIO, "Sierra VMD Audio (ffmpeg)"}, + {BUF_AUDIO_FLAC, CODEC_ID_FLAC, "FLAC (ffmpeg)"}, + {BUF_AUDIO_SHORTEN, CODEC_ID_SHORTEN, "Shorten (ffmpeg)"}, + {BUF_AUDIO_ALAC, CODEC_ID_ALAC, "ALAC (ffmpeg)"}, + {BUF_AUDIO_QDESIGN2, CODEC_ID_QDM2, "QDesign (ffmpeg)"}, + {BUF_AUDIO_COOK, CODEC_ID_COOK, "RealAudio Cooker (ffmpeg)"}, + {BUF_AUDIO_TRUESPEECH, CODEC_ID_TRUESPEECH, "TrueSpeech (ffmpeg)"}, + {BUF_AUDIO_TTA, CODEC_ID_TTA, "True Audio Lossless (ffmpeg)"}, + {BUF_AUDIO_SMACKER, CODEC_ID_SMACKAUDIO, "Smacker (ffmpeg)"}, + {BUF_AUDIO_FLVADPCM, CODEC_ID_ADPCM_SWF, "Flash ADPCM (ffmpeg)"}, + {BUF_AUDIO_WAVPACK, CODEC_ID_WAVPACK, "WavPack (ffmpeg)"}, +}; + + + static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) { + if (size > this->bufsize) { + this->bufsize = size + size / 2; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc( this->buf, this->bufsize ); + } +} + +static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + int bytes_consumed; + int decode_buffer_size; + int offset; + int out; + audio_buffer_t *audio_buffer; + int bytes_to_send; + + if ( (buf->decoder_flags & BUF_FLAG_HEADER) && + !(buf->decoder_flags & BUF_FLAG_SPECIAL) ) { + + /* accumulate init data */ + ff_audio_ensure_buffer_size(this, this->size + buf->size); + memcpy(this->buf + this->size, buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + size_t i; + unsigned int codec_type; + xine_waveformatex *audio_header; + + codec_type = buf->type & 0xFFFF0000; + this->codec = NULL; + + for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) + if(ff_audio_lookup[i].type == codec_type) { + pthread_mutex_lock (&ffmpeg_lock); + this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); + pthread_mutex_unlock (&ffmpeg_lock); + _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, + ff_audio_lookup[i].name); + break; + } + + if (!this->codec) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), + codec_type); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + + this->context = avcodec_alloc_context(); + + if(buf->decoder_flags & BUF_FLAG_STDHEADER) { + this->audio_sample_rate = buf->decoder_info[1]; + this->audio_channels = buf->decoder_info[3]; + + if(this->size) { + audio_header = (xine_waveformatex *)this->buf; + + this->context->block_align = audio_header->nBlockAlign; + this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; + + if(audio_header->cbSize > 0) { + this->context->extradata = xine_xmalloc(audio_header->cbSize); + this->context->extradata_size = audio_header->cbSize; + memcpy( this->context->extradata, + (uint8_t *)audio_header + sizeof(xine_waveformatex), + audio_header->cbSize ); + } + } + } else { + short *ptr; + + switch(codec_type) { + case BUF_AUDIO_14_4: + this->audio_sample_rate = 8000; + this->audio_channels = 1; + + this->context->block_align = 240; + break; + case BUF_AUDIO_28_8: + this->audio_sample_rate = BE_16(&this->buf[0x30]); + this->audio_channels = this->buf[0x37]; + /* this->audio_bits = buf->content[0x35] */ + + this->context->block_align = BE_16(&this->buf[0x2A]); + + this->context->extradata_size = 5*sizeof(short); + this->context->extradata = xine_xmalloc(this->context->extradata_size); + + ptr = (short *) this->context->extradata; + + ptr[0] = BE_16(&this->buf[0x2C]); /* subpacket size */ + ptr[1] = BE_16(&this->buf[0x28]); /* subpacket height */ + ptr[2] = BE_16(&this->buf[0x16]); /* subpacket flavour */ + ptr[3] = BE_32(&this->buf[0x18]); /* coded frame size */ + ptr[4] = 0; /* codec's data length */ + break; + default: + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type); + break; + } + } + + /* Current ffmpeg audio decoders always use 16 bits/sample + * buf->decoder_info[2] can't be used as it doesn't refer to the output + * bits/sample for some codecs (e.g. MS ADPCM) */ + this->audio_bits = 16; + + this->context->bits_per_sample = this->audio_bits; + this->context->sample_rate = this->audio_sample_rate; + this->context->channels = this->audio_channels; + this->context->codec_id = this->codec->id; + this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); + + this->size = 0; + + this->decode_buffer = xine_xmalloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); + + return; + } + } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && + (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) { + + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = xine_xmalloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + + } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { + + if( !this->decoder_ok ) { + if ( ! this->context || ! this->codec ) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: trying to open null codec\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + + pthread_mutex_lock (&ffmpeg_lock); + if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock (&ffmpeg_lock); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: couldn't open decoder\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + pthread_mutex_unlock (&ffmpeg_lock); + this->decoder_ok = 1; + } + + if (!this->output_open) { + this->output_open = this->stream->audio_out->open(this->stream->audio_out, + this->stream, this->audio_bits, this->audio_sample_rate, + _x_ao_channels2mode(this->audio_channels)); + } + + /* if the audio still isn't open, bail */ + if (!this->output_open) + return; + + if( buf->decoder_flags & BUF_FLAG_PREVIEW ) + return; + + ff_audio_ensure_buffer_size(this, this->size + buf->size); + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ + + offset = 0; + while (this->size>0) { + decode_buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; + bytes_consumed = avcodec_decode_audio2 (this->context, + (int16_t *)this->decode_buffer, + &decode_buffer_size, + &this->buf[offset], + this->size); + + if (bytes_consumed<0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_audio_dec: error decompressing audio frame\n"); + this->size=0; + return; + } else if (bytes_consumed == 0 && decode_buffer_size == 0) { + if (offset) + memmove(this->buf, &this->buf[offset], this->size); + return; + } + + /* dispatch the decoded audio */ + out = 0; + while (out < decode_buffer_size) { + audio_buffer = + this->stream->audio_out->get_buffer (this->stream->audio_out); + if (audio_buffer->mem_size == 0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_audio_dec: Help! Allocated audio buffer with nothing in it!\n"); + return; + } + + if ((decode_buffer_size - out) > audio_buffer->mem_size) + bytes_to_send = audio_buffer->mem_size; + else + bytes_to_send = decode_buffer_size - out; + + /* fill up this buffer */ + xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], + bytes_to_send); + /* byte count / 2 (bytes / sample) / channels */ + audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; + + audio_buffer->vpts = buf->pts; + buf->pts = 0; /* only first buffer gets the real pts */ + this->stream->audio_out->put_buffer (this->stream->audio_out, + audio_buffer, this->stream); + + out += bytes_to_send; + } + + this->size -= bytes_consumed; + offset += bytes_consumed; + } + + /* reset internal accumulation buffer */ + this->size = 0; + } + } +} + +static void ff_audio_reset (audio_decoder_t *this_gen) { + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + + this->size = 0; + + /* try to reset the wma decoder */ + if( this->context && this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); + avcodec_close (this->context); + avcodec_open (this->context, this->codec); + pthread_mutex_unlock (&ffmpeg_lock); + } +} + +static void ff_audio_discontinuity (audio_decoder_t *this_gen) { +} + +static void ff_audio_dispose (audio_decoder_t *this_gen) { + + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + + if( this->context && this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); + avcodec_close (this->context); + pthread_mutex_unlock (&ffmpeg_lock); + } + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + free(this->buf); + free(this->decode_buffer); + + if(this->context && this->context->extradata) + free(this->context->extradata); + + if(this->context) + free(this->context); + + free (this_gen); +} + +static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + ff_audio_decoder_t *this ; + + this = (ff_audio_decoder_t *) xine_xmalloc (sizeof (ff_audio_decoder_t)); + + this->audio_decoder.decode_data = ff_audio_decode_data; + this->audio_decoder.reset = ff_audio_reset; + this->audio_decoder.discontinuity = ff_audio_discontinuity; + this->audio_decoder.dispose = ff_audio_dispose; + + this->output_open = 0; + this->audio_channels = 0; + this->stream = stream; + this->buf = NULL; + this->size = 0; + this->bufsize = 0; + this->decoder_ok = 0; + + ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE); + + return &this->audio_decoder; +} + +static char *ff_audio_get_identifier (audio_decoder_class_t *this) { + return "ffmpeg audio"; +} + +static char *ff_audio_get_description (audio_decoder_class_t *this) { + return "ffmpeg based audio decoder plugin"; +} + +static void ff_audio_dispose_class (audio_decoder_class_t *this) { + free (this); +} + +void *init_audio_plugin (xine_t *xine, void *data) { + + ff_audio_class_t *this ; + + this = (ff_audio_class_t *) xine_xmalloc (sizeof (ff_audio_class_t)); + + this->decoder_class.open_plugin = ff_audio_open_plugin; + this->decoder_class.get_identifier = ff_audio_get_identifier; + this->decoder_class.get_description = ff_audio_get_description; + this->decoder_class.dispose = ff_audio_dispose_class; + + pthread_once( &once_control, init_once_routine ); + + return this; +} + +static uint32_t supported_audio_types[] = { + #ifdef CONFIG_WMAV1_DECODER + BUF_AUDIO_WMAV1, + #endif + #ifdef CONFIG_WMAV2_DECODER + BUF_AUDIO_WMAV2, + #endif + #ifdef CONFIG_RA_144_DECODER + BUF_AUDIO_14_4, + #endif + #ifdef CONFIG_RA_288_DECODER + BUF_AUDIO_28_8, + #endif + #ifdef CONFIG_MP3_DECODER + BUF_AUDIO_MPEG, + #endif + #ifdef CONFIG_ADPCM_MS_DECODER + BUF_AUDIO_MSADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_QT_DECODER + BUF_AUDIO_QTIMAADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_WAV_DECODER + BUF_AUDIO_MSIMAADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_DK3_DECODER + BUF_AUDIO_DK3ADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_DK4_DECODER + BUF_AUDIO_DK4ADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_WS_DECODER + BUF_AUDIO_VQA_IMA, + #endif + #ifdef CONFIG_ADPCM_IMA_SMJPEG_DECODER + BUF_AUDIO_SMJPEG_IMA, + #endif + #ifdef CONFIG_ADPCM_XA_DECODER + BUF_AUDIO_XA_ADPCM, + #endif + #ifdef CONFIG_ADPCM_4XM_DECODER + BUF_AUDIO_4X_ADPCM, + #endif + #ifdef CONFIG_ADPCM_EA_DECODER + BUF_AUDIO_EA_ADPCM, + #endif + #ifdef CONFIG_PCM_MULAW_DECODER + BUF_AUDIO_MULAW, + #endif + #ifdef CONFIG_PCM_ALAW_DECODER + BUF_AUDIO_ALAW, + #endif + #ifdef CONFIG_ROQ_DPCM_DECODER + BUF_AUDIO_ROQ, + #endif + #ifdef CONFIG_INTERPLAY_DPCM_DECODER + BUF_AUDIO_INTERPLAY, + #endif + #ifdef CONFIG_MACE3_DECODER + BUF_AUDIO_MAC3, + #endif + #ifdef CONFIG_MACE6_DECODER + BUF_AUDIO_MAC6, + #endif + #ifdef CONFIG_XAN_DPCM_DECODER + BUF_AUDIO_XAN_DPCM, + #endif + #ifdef CONFIG_VMDAUDIO_DECODER + BUF_AUDIO_VMD, + #endif + #ifdef CONFIG_FLAC_DECODER + BUF_AUDIO_FLAC, + #endif + #ifdef CONFIG_SHORTEN_DECODER + BUF_AUDIO_SHORTEN, + #endif + #ifdef CONFIG_ALAC_DECODER + BUF_AUDIO_ALAC, + #endif + #ifdef CONFIG_QDM2_DECODER + BUF_AUDIO_QDESIGN2, + #endif + #ifdef CONFIG_COOK_DECODER + BUF_AUDIO_COOK, + #endif + #ifdef CONFIG_TRUESPEECH_DECODER + BUF_AUDIO_TRUESPEECH, + #endif + #ifdef CONFIG_TTA_DECODER + BUF_AUDIO_TTA, + #endif + #ifdef CONFIG_SMACKAUDIO_DECODER + BUF_AUDIO_SMACKER, + #endif + #ifdef CONFIG_ADPCM_SWF_DECODER + BUF_AUDIO_FLVADPCM, + #endif + #ifdef CONFIG_WAVPACK_DECODER + BUF_AUDIO_WAVPACK, + #endif + + 0 +}; + +decoder_info_t dec_info_ffmpeg_audio = { + supported_audio_types, /* supported types */ + 6 /* priority */ +}; diff --git a/src/libffmpeg/ff_dvaudio_decoder.c b/src/libffmpeg/ff_dvaudio_decoder.c new file mode 100644 index 000000000..2c851bae1 --- /dev/null +++ b/src/libffmpeg/ff_dvaudio_decoder.c @@ -0,0 +1,433 @@ +/* + * Copyright (C) 2005 the xine project + * + * This file is part of xine, a free 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: dvaudio_decoder.c,v 1.12 2006/12/04 22:25:13 miguelfreitas Exp $ + * + * dv audio decoder based on patch by Dan Dennedy + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#define LOG_MODULE "dvaudio" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "buffer.h" +#include "xineutils.h" + +#ifdef _MSC_VER +/* ffmpeg has own definitions of those types */ +# undef int8_t +# undef uint8_t +# undef int16_t +# undef uint16_t +# undef int32_t +# undef uint32_t +# undef int64_t +# undef uint64_t +#endif + +#ifdef HAVE_FFMPEG +# include +# include "libavcodec/dvdata.h" +#else +# include "libavcodec/avcodec.h" +# include "libavcodec/dvdata.h" +#endif + +#ifdef _MSC_VER +# undef malloc +# undef free +# undef realloc +#endif + +#define AUDIOBUFSIZE 128*1024 +#define MAXFRAMESIZE 131072 + + +typedef struct { + audio_decoder_class_t decoder_class; +} dvaudio_class_t; + +typedef struct dvaudio_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + int output_open; + int audio_channels; + int audio_bits; + int audio_sample_rate; + + unsigned char *buf; + int bufsize; + int size; + + char *decode_buffer; + int decoder_ok; + +} dvaudio_decoder_t; + + +/* + * This is the dumbest implementation of all -- it simply looks at + * a fixed offset and if pack isn't there -- fails. We might want + * to have a fallback mechanism for complete search of missing packs. + */ +static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) +{ + int offs; + + switch (t) { + case dv_audio_source: + offs = (80*6 + 80*16*3 + 3); + break; + case dv_audio_control: + offs = (80*6 + 80*16*4 + 3); + break; + case dv_video_control: + offs = (80*5 + 48 + 5); + break; + default: + return NULL; + } + + return (frame[offs] == t ? &frame[offs] : NULL); +} + +static inline uint16_t dv_audio_12to16(uint16_t sample) +{ + uint16_t shift, result; + + sample = (sample < 0x800) ? sample : sample | 0xf000; + shift = (sample & 0xf00) >> 8; + + if (shift < 0x2 || shift > 0xd) { + result = sample; + } else if (shift < 0x8) { + shift--; + result = (sample - (256 * shift)) << shift; + } else { + shift = 0xe - shift; + result = ((sample + ((256 * shift) + 1)) << shift) - 1; + } + + return result; +} + +/* + * There's a couple of assumptions being made here: + * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. + * We can pass them upwards when ffmpeg will be ready to deal with them. + * 2. We don't do software emphasis. + * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples + * are converted into 16bit linear ones. + */ +static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2) +{ + int size, i, j, d, of, smpls, freq, quant, half_ch; + uint16_t lc, rc; + const DVprofile* sys; + const uint8_t* as_pack; + + as_pack = dv_extract_pack(frame, dv_audio_source); + if (!as_pack) /* No audio ? */ + return 0; + + sys = dv_frame_profile(frame); + smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ + freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ + quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ + + if (quant > 1) + return -1; /* Unsupported quantization */ + + size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ + half_ch = sys->difseg_size/2; + + /* for each DIF segment */ + for (i = 0; i < sys->difseg_size; i++) { + frame += 6 * 80; /* skip DIF segment header */ + if (quant == 1 && i == half_ch) { + if (!pcm2) + break; + else + pcm = pcm2; + } + + for (j = 0; j < 9; j++) { + for (d = 8; d < 80; d += 2) { + if (quant == 0) { /* 16bit quantization */ + of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; + if (of*2 >= size) + continue; + +#ifdef WORDS_BIGENDIAN + pcm[of*2] = frame[d]; + pcm[of*2+1] = frame[d+1]; +#else + pcm[of*2] = frame[d+1]; + pcm[of*2+1] = frame[d]; +#endif + if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) + pcm[of*2+1] = 0; + } else { /* 12bit quantization */ + lc = ((uint16_t)frame[d] << 4) | + ((uint16_t)frame[d+2] >> 4); + rc = ((uint16_t)frame[d+1] << 4) | + ((uint16_t)frame[d+2] & 0x0f); + lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); + rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); + + of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; + if (of*2 >= size) + continue; + +#ifdef WORDS_BIGENDIAN + pcm[of*2] = lc >> 8; + pcm[of*2+1] = lc & 0xff; +#else + pcm[of*2] = lc & 0xff; + pcm[of*2+1] = lc >> 8; +#endif + of = sys->audio_shuffle[i%half_ch+half_ch][j] + + (d - 8)/3 * sys->audio_stride; +#ifdef WORDS_BIGENDIAN + pcm[of*2] = rc >> 8; + pcm[of*2+1] = rc & 0xff; +#else + pcm[of*2] = rc & 0xff; + pcm[of*2+1] = rc >> 8; +#endif + ++d; + } + } + + frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ + } + } + + return size; +} + +static void dvaudio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; + int bytes_consumed; + int decode_buffer_size; + int offset; + int out; + audio_buffer_t *audio_buffer; + int bytes_to_send; + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + if (buf->decoder_flags & BUF_FLAG_STDHEADER) { + this->buf = xine_xmalloc(AUDIOBUFSIZE); + this->bufsize = AUDIOBUFSIZE; + this->size = 0; + this->decode_buffer = xine_xmalloc(MAXFRAMESIZE); + + this->audio_sample_rate = buf->decoder_info[1]; + this->audio_bits = buf->decoder_info[2]; + this->audio_channels = buf->decoder_info[3]; + + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DV Audio"); + + this->decoder_ok = 1; + + return; + } + + if (this->decoder_ok && !(buf->decoder_flags & (BUF_FLAG_HEADER|BUF_FLAG_SPECIAL))) { + + if (!this->output_open) { + this->output_open = this->stream->audio_out->open(this->stream->audio_out, + this->stream, this->audio_bits, this->audio_sample_rate, + _x_ao_channels2mode(this->audio_channels)); + } + + /* if the audio still isn't open, bail */ + if (!this->output_open) + return; + + if( this->size + buf->size > this->bufsize ) { + this->bufsize = this->size + 2 * buf->size; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("dvaudio: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc( this->buf, this->bufsize ); + } + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ + + offset = 0; + while (this->size>0) { + decode_buffer_size = dv_extract_audio(&this->buf[offset], this->decode_buffer, NULL); + + if (decode_buffer_size > -1) + bytes_consumed = dv_frame_profile(&this->buf[offset])->frame_size; + else + bytes_consumed = decode_buffer_size; + + /* dispatch the decoded audio */ + out = 0; + while (out < decode_buffer_size) { + audio_buffer = + this->stream->audio_out->get_buffer (this->stream->audio_out); + if (audio_buffer->mem_size == 0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "dvaudio: Help! Allocated audio buffer with nothing in it!\n"); + return; + } + + if ((decode_buffer_size - out) > audio_buffer->mem_size) + bytes_to_send = audio_buffer->mem_size; + else + bytes_to_send = decode_buffer_size - out; + + /* fill up this buffer */ + xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], + bytes_to_send); + /* byte count / 2 (bytes / sample) / channels */ + audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; + + audio_buffer->vpts = buf->pts; + buf->pts = 0; /* only first buffer gets the real pts */ + this->stream->audio_out->put_buffer (this->stream->audio_out, + audio_buffer, this->stream); + + out += bytes_to_send; + } + + this->size -= bytes_consumed; + offset += bytes_consumed; + } + + /* reset internal accumulation buffer */ + this->size = 0; + } + } +} + +static void dvaudio_reset (audio_decoder_t *this_gen) { + dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; + + this->size = 0; +} + +static void dvaudio_discontinuity (audio_decoder_t *this_gen) { +} + +static void dvaudio_dispose (audio_decoder_t *this_gen) { + + dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + free(this->buf); + free(this->decode_buffer); + + free (this_gen); +} + +static audio_decoder_t *dvaudio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + dvaudio_decoder_t *this ; + + this = (dvaudio_decoder_t *) xine_xmalloc (sizeof (dvaudio_decoder_t)); + + this->audio_decoder.decode_data = dvaudio_decode_data; + this->audio_decoder.reset = dvaudio_reset; + this->audio_decoder.discontinuity = dvaudio_discontinuity; + this->audio_decoder.dispose = dvaudio_dispose; + + this->output_open = 0; + this->audio_channels = 0; + this->stream = stream; + this->buf = NULL; + this->size = 0; + this->decoder_ok = 0; + + return &this->audio_decoder; +} + +static char *dvaudio_get_identifier (audio_decoder_class_t *this) { + return "dv audio"; +} + +static char *dvaudio_get_description (audio_decoder_class_t *this) { + return "dv audio decoder plugin"; +} + +static void dvaudio_dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_dvaudio_plugin (xine_t *xine, void *data) { + + dvaudio_class_t *this ; + + this = (dvaudio_class_t *) xine_xmalloc (sizeof (dvaudio_class_t)); + + this->decoder_class.open_plugin = dvaudio_open_plugin; + this->decoder_class.get_identifier = dvaudio_get_identifier; + this->decoder_class.get_description = dvaudio_get_description; + this->decoder_class.dispose = dvaudio_dispose_class; + + return this; +} + +static uint32_t supported_audio_types[] = { + BUF_AUDIO_DV, + 0 +}; + +static const decoder_info_t dec_info_dvaudio = { + supported_audio_types, /* supported types */ + 5 /* priority */ +}; + +/* + * exported plugin catalog entry + */ + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "dvaudio", XINE_VERSION_CODE, &dec_info_dvaudio, init_dvaudio_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/libffmpeg/ff_mpeg_parser.c b/src/libffmpeg/ff_mpeg_parser.c new file mode 100644 index 000000000..fcee29a80 --- /dev/null +++ b/src/libffmpeg/ff_mpeg_parser.c @@ -0,0 +1,323 @@ +/* + * Copyright (C) 2001-2004 the xine project + * + * This file is part of xine, a free 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 + * + * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) + * based on libmpeg2 decoder. + * + * $Id: mpeg_parser.c,v 1.7 2007/03/29 18:52:45 dgp85 Exp $ + */ +#define LOG_MODULE "mpeg_parser" +#define LOG_VERBOSE +/* +#define LOG +*/ +#include "ff_mpeg_parser.h" + +/* mpeg frame rate table from lavc */ +static const int frame_rate_tab[][2] = { + { 0, 0}, + {24000, 1001}, + { 24, 1}, + { 25, 1}, + {30000, 1001}, + { 30, 1}, + { 50, 1}, + {60000, 1001}, + { 60, 1}, + /* Xing's 15fps: (9) */ + { 15, 1}, + /* libmpeg3's "Unofficial economy rates": (10-13) */ + { 5, 1}, + { 10, 1}, + { 12, 1}, + { 15, 1}, + { 0, 0}, +}; + +void mpeg_parser_init (mpeg_parser_t *parser) +{ + parser->chunk_buffer = xine_xmalloc(BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); + mpeg_parser_reset(parser); +} + +void mpeg_parser_dispose (mpeg_parser_t *parser) +{ + if ( parser == NULL ) return; + + free(parser->chunk_buffer); +} + +void mpeg_parser_reset (mpeg_parser_t *parser) +{ + parser->shift = 0xffffff00; + parser->is_sequence_needed = 1; + parser->in_slice = 0; + parser->chunk_ptr = parser->chunk_buffer; + parser->chunk_start = parser->chunk_buffer; + parser->buffer_size = 0; + parser->code = 0xb4; + parser->picture_coding_type = 0; + parser->width = 0; + parser->height = 0; + parser->rate_code = 0; + parser->aspect_ratio_info = 0; + parser->frame_duration = 0; + parser->is_mpeg1 = 0; + parser->has_sequence = 0; + parser->frame_aspect_ratio = 0.0; +} + +static void parse_header_picture (mpeg_parser_t *parser, uint8_t * buffer) +{ + parser->picture_coding_type = (buffer [1] >> 3) & 7; +} + +static double get_aspect_ratio(mpeg_parser_t *parser) +{ + double ratio; + double mpeg1_pel_ratio[16] = {1.0 /* forbidden */, + 1.0, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, + 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 1.0 /*reserved*/ }; + + if( !parser->is_mpeg1 ) { + /* these hardcoded values are defined on mpeg2 standard for + * aspect ratio. other values are reserved or forbidden. */ + switch (parser->aspect_ratio_info) { + case 2: + ratio = 4.0 / 3.0; + break; + case 3: + ratio = 16.0 / 9.0; + break; + case 4: + ratio = 2.11 / 1.0; + break; + case 1: + default: + ratio = (double)parser->width / (double)parser->height; + break; + } + } else { + /* mpeg1 constants refer to pixel aspect ratio */ + ratio = (double)parser->width / (double)parser->height; + ratio /= mpeg1_pel_ratio[parser->aspect_ratio_info]; + } + + return ratio; +} + +static int parse_chunk (mpeg_parser_t *parser, int code, uint8_t *buffer, int len) +{ + int is_frame_done; + int next_code = parser->code; + + /* wait for sequence_header_code */ + if (parser->is_sequence_needed) { + if (code != 0xb3) { + lprintf("waiting for sequence header\n"); + parser->chunk_ptr = parser->chunk_buffer; + return 0; + } + } + + is_frame_done = parser->in_slice && ((!next_code) || (next_code == 0xb7)); + + if (is_frame_done) + parser->in_slice = 0; + + switch (code) { + case 0x00: /* picture_start_code */ + + parse_header_picture (parser, buffer); + + parser->in_slice = 1; + + switch (parser->picture_coding_type) { + case B_TYPE: + lprintf ("B-Frame\n"); + break; + + case P_TYPE: + lprintf ("P-Frame\n"); + break; + + case I_TYPE: + lprintf ("I-Frame\n"); + break; + } + break; + + case 0xb2: /* user data code */ + /* process_userdata(mpeg2dec, buffer); */ + break; + + case 0xb3: /* sequence_header_code */ + { + int value; + uint16_t width, height; + + if (parser->is_sequence_needed) { + parser->is_sequence_needed = 0; + } + + if ((buffer[6] & 0x20) != 0x20) { + lprintf("Invalid sequence: missing marker_bit\n"); + parser->has_sequence = 0; + break; /* missing marker_bit */ + } + + value = (buffer[0] << 16) | + (buffer[1] << 8) | + buffer[2]; + width = ((value >> 12) + 15) & ~15; + height = ((value & 0xfff) + 15) & ~15; + + if ((width > 1920) || (height > 1152)) { + lprintf("Invalid sequence: width=%d, height=%d\n", width, height); + parser->has_sequence = 0; + break; /* size restrictions for MP@HL */ + } + + parser->width = width; + parser->height = height; + parser->rate_code = buffer[3] & 15; + parser->aspect_ratio_info = buffer[3] >> 4; + + if (parser->rate_code < (sizeof(frame_rate_tab)/sizeof(*frame_rate_tab))) { + parser->frame_duration = 90000; + parser->frame_duration *= frame_rate_tab[parser->rate_code][1]; + parser->frame_duration /= frame_rate_tab[parser->rate_code][0]; + } else { + printf ("invalid/unknown frame rate code : %d \n", + parser->rate_code); + parser->frame_duration = 0; + } + + parser->has_sequence = 1; + parser->is_mpeg1 = 1; + } + break; + + case 0xb5: /* extension_start_code */ + switch (buffer[0] & 0xf0) { + case 0x10: /* sequence extension */ + parser->is_mpeg1 = 0; + } + + default: + if (code >= 0xb9) + lprintf ("stream not demultiplexed ?\n"); + + if (code >= 0xb0) + break; + } + return is_frame_done; +} + +static inline uint8_t *copy_chunk (mpeg_parser_t *parser, + uint8_t *current, uint8_t *end) +{ + uint32_t shift; + uint8_t *chunk_ptr; + uint8_t *limit; + uint8_t byte; + + shift = parser->shift; + chunk_ptr = parser->chunk_ptr; + + limit = current + (parser->chunk_buffer + BUFFER_SIZE - chunk_ptr); + if (limit > end) + limit = end; + + while (1) { + + byte = *current++; + *chunk_ptr++ = byte; + if (shift != 0x00000100) { + shift = (shift | byte) << 8; + if (current < limit) + continue; + if (current == end) { + parser->chunk_ptr = chunk_ptr; + parser->shift = shift; + lprintf("Need more bytes\n"); + return NULL; + } else { + /* we filled the chunk buffer without finding a start code */ + lprintf("Buffer full\n"); + parser->code = 0xb4; /* sequence_error_code */ + parser->chunk_ptr = parser->chunk_buffer; + return current; + } + } + lprintf("New chunk: 0x%2X\n", byte); + parser->chunk_ptr = chunk_ptr; + parser->shift = 0xffffff00; + parser->code = byte; + return current; + } +} + + +uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, + uint8_t *current, uint8_t *end, + int *flush) +{ + int ret; + uint8_t code; + + ret = 0; + *flush = 0; + + while (current != end) { + if (parser->chunk_ptr == parser->chunk_buffer) { + /* write the beginning of the chunk */ + parser->chunk_buffer[0] = 0x00; + parser->chunk_buffer[1] = 0x00; + parser->chunk_buffer[2] = 0x01; + parser->chunk_buffer[3] = parser->code; + parser->chunk_ptr += 4; + parser->chunk_start = parser->chunk_ptr; + parser->has_sequence = 0; + } + + code = parser->code; + + current = copy_chunk (parser, current, end); + if (current == NULL) + return NULL; + ret = parse_chunk (parser, code, parser->chunk_start, + parser->chunk_ptr - parser->chunk_start - 4); + parser->chunk_start = parser->chunk_ptr; + if (ret == 1) { + if (parser->has_sequence) { + parser->frame_aspect_ratio = get_aspect_ratio(parser); + } + parser->buffer_size = parser->chunk_ptr - parser->chunk_buffer - 4; + parser->chunk_ptr = parser->chunk_buffer; + + if (parser->code == 0xb7) /* sequence end, maybe a still menu */ + *flush = 1; + + return current; + } + } + + return NULL; +} diff --git a/src/libffmpeg/ff_mpeg_parser.h b/src/libffmpeg/ff_mpeg_parser.h new file mode 100644 index 000000000..b307714cc --- /dev/null +++ b/src/libffmpeg/ff_mpeg_parser.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2001-2004 the xine project + * + * This file is part of xine, a free 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 + * + * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) + * based on libmpeg2 decoder. + * + * $Id: mpeg_parser.h,v 1.5 2007/03/29 18:52:45 dgp85 Exp $ + */ +#ifndef HAVE_MPEG_PARSER_H +#define HAVE_MPEG_PARSER_H + +#include "xine_internal.h" +#include "ffmpeg_decoder.h" + +#define BUFFER_SIZE (1194 * 1024) /* libmpeg2's buffer size */ + +/* picture coding type (mpeg2 header) */ +#define I_TYPE 1 +#define P_TYPE 2 +#define B_TYPE 3 +#define D_TYPE 4 + +typedef struct mpeg_parser_s { + uint8_t *chunk_buffer; + uint8_t *chunk_ptr; + uint8_t *chunk_start; + uint32_t shift; + int buffer_size; + uint8_t code; + uint8_t picture_coding_type; + + uint8_t is_sequence_needed:1; + uint8_t is_mpeg1:1; /* public */ + uint8_t has_sequence:1; /* public */ + uint8_t in_slice:1; + + uint8_t rate_code:4; + + int aspect_ratio_info; + + /* public properties */ + uint16_t width; + uint16_t height; + int frame_duration; + double frame_aspect_ratio; + +} mpeg_parser_t; + +/* parser initialization */ +void mpeg_parser_init (mpeg_parser_t *parser); + +/* parser disposal */ +void mpeg_parser_dispose (mpeg_parser_t *parser); + +/* read a frame + * return a pointer to the first byte of the next frame + * or NULL if more bytes are needed + * *flush is set to 1 if the decoder must be flushed (needed for still menus) + */ +uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, + uint8_t *current, uint8_t *end, + int *flush); + +/* reset the parser */ +void mpeg_parser_reset (mpeg_parser_t *parser); + +#endif /* HAVE_MPEG_PARSER_H */ diff --git a/src/libffmpeg/ff_video_decoder.c b/src/libffmpeg/ff_video_decoder.c new file mode 100644 index 000000000..e04c680b7 --- /dev/null +++ b/src/libffmpeg/ff_video_decoder.c @@ -0,0 +1,1772 @@ +/* + * Copyright (C) 2001-2007 the xine project + * + * This file is part of xine, a free 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: video_decoder.c,v 1.73 2007/03/29 18:41:02 dgp85 Exp $ + * + * xine video decoder plugin using ffmpeg + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "ffmpeg_config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "ffmpeg_video_dec" +#define LOG_VERBOSE +/* +#define LOG +*/ +#include "xine_internal.h" +#include "bswap.h" +#include "buffer.h" +#include "xineutils.h" +#include "ffmpeg_decoder.h" +#include "ff_mpeg_parser.h" + +#ifdef HAVE_FFMPEG +# include +#else +# include "libavcodec/libpostproc/postprocess.h" +#endif + +#define VIDEOBUFSIZE (128*1024) +#define SLICE_BUFFER_SIZE (1194*1024) + +#define SLICE_OFFSET_SIZE 128 + +#define ENABLE_DIRECT_RENDERING + +typedef struct ff_video_decoder_s ff_video_decoder_t; + +typedef struct ff_video_class_s { + video_decoder_class_t decoder_class; + + int pp_quality; + + xine_t *xine; +} ff_video_class_t; + +struct ff_video_decoder_s { + video_decoder_t video_decoder; + + ff_video_class_t *class; + + xine_stream_t *stream; + int64_t pts; + int video_step; + + uint8_t decoder_ok:1; + uint8_t decoder_init_mode:1; + uint8_t is_mpeg12:1; + uint8_t pp_available:1; + uint8_t yuv_init:1; + uint8_t is_direct_rendering_disabled:1; + uint8_t cs_convert_init:1; + + xine_bmiheader bih; + unsigned char *buf; + int bufsize; + int size; + int skipframes; + + int slice_offset_size; + + AVFrame *av_frame; + AVCodecContext *context; + AVCodec *codec; + + int pp_quality; + int pp_flags; + pp_context_t *pp_context; + pp_mode_t *pp_mode; + + /* mpeg-es parsing */ + mpeg_parser_t *mpeg_parser; + + double aspect_ratio; + int aspect_ratio_prio; + int frame_flags; + int crop_right, crop_bottom; + + int output_format; + + xine_list_t *dr1_frames; + + yuv_planes_t yuv; + + AVPaletteControl palette_control; +}; + + +static void set_stream_info(ff_video_decoder_t *this) { + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->bih.biWidth); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->bih.biHeight); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, this->aspect_ratio * 10000); +} + +#ifdef ENABLE_DIRECT_RENDERING +/* called from ffmpeg to do direct rendering method 1 */ +static int get_buffer(AVCodecContext *context, AVFrame *av_frame){ + ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; + vo_frame_t *img; + int width = context->width; + int height = context->height; + + if (!this->bih.biWidth || !this->bih.biHeight) { + this->bih.biWidth = width; + this->bih.biHeight = height; + + if (this->aspect_ratio_prio == 0) { + this->aspect_ratio = (double)width / (double)height; + this->aspect_ratio_prio = 1; + lprintf("default aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + } + + avcodec_align_dimensions(context, &width, &height); + + if( this->context->pix_fmt != PIX_FMT_YUV420P ) { + if (!this->is_direct_rendering_disabled) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n")); + this->is_direct_rendering_disabled = 1; + } + + /* FIXME: why should i have to do that ? */ + av_frame->data[0]= NULL; + av_frame->data[1]= NULL; + av_frame->data[2]= NULL; + return avcodec_default_get_buffer(context, av_frame); + } + + if((width != this->bih.biWidth) || (height != this->bih.biHeight)) { + if(this->stream->video_out->get_capabilities(this->stream->video_out) & VO_CAP_CROP) { + this->crop_right = width - this->bih.biWidth; + this->crop_bottom = height - this->bih.biHeight; + } else { + if (!this->is_direct_rendering_disabled) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n")); + this->is_direct_rendering_disabled = 1; + } + /* FIXME: why should i have to do that ? */ + av_frame->data[0]= NULL; + av_frame->data[1]= NULL; + av_frame->data[2]= NULL; + return avcodec_default_get_buffer(context, av_frame); + } + } + + img = this->stream->video_out->get_frame (this->stream->video_out, + width, + height, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + + av_frame->opaque = img; + + av_frame->data[0]= img->base[0]; + av_frame->data[1]= img->base[1]; + av_frame->data[2]= img->base[2]; + + av_frame->linesize[0] = img->pitches[0]; + av_frame->linesize[1] = img->pitches[1]; + av_frame->linesize[2] = img->pitches[2]; + + /* We should really keep track of the ages of xine frames (see + * avcodec_default_get_buffer in libavcodec/utils.c) + * For the moment tell ffmpeg that every frame is new (age = bignumber) */ + av_frame->age = 256*256*256*64; + + av_frame->type= FF_BUFFER_TYPE_USER; + + xine_list_push_back(this->dr1_frames, av_frame); + + return 0; +} + +static void release_buffer(struct AVCodecContext *context, AVFrame *av_frame){ + ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; + + if (av_frame->type == FF_BUFFER_TYPE_USER) { + vo_frame_t *img = (vo_frame_t *)av_frame->opaque; + xine_list_iterator_t it; + + assert(av_frame->opaque); + img->free(img); + + it = xine_list_find(this->dr1_frames, av_frame); + assert(it); + if( it != NULL ) + xine_list_remove(this->dr1_frames, it); + } else { + avcodec_default_release_buffer(context, av_frame); + } + + av_frame->opaque = NULL; + av_frame->data[0]= NULL; + av_frame->data[1]= NULL; + av_frame->data[2]= NULL; +} +#endif + +static const ff_codec_t ff_video_lookup[] = { + {BUF_VIDEO_MSMPEG4_V1, CODEC_ID_MSMPEG4V1, "Microsoft MPEG-4 v1 (ffmpeg)"}, + {BUF_VIDEO_MSMPEG4_V2, CODEC_ID_MSMPEG4V2, "Microsoft MPEG-4 v2 (ffmpeg)"}, + {BUF_VIDEO_MSMPEG4_V3, CODEC_ID_MSMPEG4V3, "Microsoft MPEG-4 v3 (ffmpeg)"}, + {BUF_VIDEO_WMV7, CODEC_ID_WMV1, "MS Windows Media Video 7 (ffmpeg)"}, + {BUF_VIDEO_WMV8, CODEC_ID_WMV2, "MS Windows Media Video 8 (ffmpeg)"}, + {BUF_VIDEO_WMV9, CODEC_ID_WMV3, "MS Windows Media Video 9 (ffmpeg)"}, + {BUF_VIDEO_MPEG4, CODEC_ID_MPEG4, "ISO MPEG-4 (ffmpeg)"}, + {BUF_VIDEO_XVID, CODEC_ID_MPEG4, "ISO MPEG-4 (XviD, ffmpeg)"}, + {BUF_VIDEO_DIVX5, CODEC_ID_MPEG4, "ISO MPEG-4 (DivX5, ffmpeg)"}, + {BUF_VIDEO_3IVX, CODEC_ID_MPEG4, "ISO MPEG-4 (3ivx, ffmpeg)"}, + {BUF_VIDEO_JPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, + {BUF_VIDEO_MJPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, + {BUF_VIDEO_MJPEG_B, CODEC_ID_MJPEGB, "Motion JPEG B (ffmpeg)"}, + {BUF_VIDEO_I263, CODEC_ID_H263I, "ITU H.263 (ffmpeg)"}, + {BUF_VIDEO_H263, CODEC_ID_H263, "H.263 (ffmpeg)"}, + {BUF_VIDEO_RV10, CODEC_ID_RV10, "Real Video 1.0 (ffmpeg)"}, + {BUF_VIDEO_RV20, CODEC_ID_RV20, "Real Video 2.0 (ffmpeg)"}, + {BUF_VIDEO_IV31, CODEC_ID_INDEO3, "Indeo Video 3.1 (ffmpeg)"}, + {BUF_VIDEO_IV32, CODEC_ID_INDEO3, "Indeo Video 3.2 (ffmpeg)"}, + {BUF_VIDEO_SORENSON_V1, CODEC_ID_SVQ1, "Sorenson Video 1 (ffmpeg)"}, + {BUF_VIDEO_SORENSON_V3, CODEC_ID_SVQ3, "Sorenson Video 3 (ffmpeg)"}, + {BUF_VIDEO_DV, CODEC_ID_DVVIDEO, "DV (ffmpeg)"}, + {BUF_VIDEO_HUFFYUV, CODEC_ID_HUFFYUV, "HuffYUV (ffmpeg)"}, + {BUF_VIDEO_VP31, CODEC_ID_VP3, "On2 VP3.1 (ffmpeg)"}, + {BUF_VIDEO_VP5, CODEC_ID_VP5, "On2 VP5 (ffmpeg)"}, + {BUF_VIDEO_VP6, CODEC_ID_VP6, "On2 VP6 (ffmpeg)"}, + {BUF_VIDEO_VP6F, CODEC_ID_VP6F, "On2 VP6 (ffmpeg)"}, + {BUF_VIDEO_4XM, CODEC_ID_4XM, "4X Video (ffmpeg)"}, + {BUF_VIDEO_CINEPAK, CODEC_ID_CINEPAK, "Cinepak (ffmpeg)"}, + {BUF_VIDEO_MSVC, CODEC_ID_MSVIDEO1, "Microsoft Video 1 (ffmpeg)"}, + {BUF_VIDEO_MSRLE, CODEC_ID_MSRLE, "Microsoft RLE (ffmpeg)"}, + {BUF_VIDEO_RPZA, CODEC_ID_RPZA, "Apple Quicktime Video/RPZA (ffmpeg)"}, + {BUF_VIDEO_CYUV, CODEC_ID_CYUV, "Creative YUV (ffmpeg)"}, + {BUF_VIDEO_ROQ, CODEC_ID_ROQ, "Id Software RoQ (ffmpeg)"}, + {BUF_VIDEO_IDCIN, CODEC_ID_IDCIN, "Id Software CIN (ffmpeg)"}, + {BUF_VIDEO_WC3, CODEC_ID_XAN_WC3, "Xan (ffmpeg)"}, + {BUF_VIDEO_VQA, CODEC_ID_WS_VQA, "Westwood Studios VQA (ffmpeg)"}, + {BUF_VIDEO_INTERPLAY, CODEC_ID_INTERPLAY_VIDEO, "Interplay MVE (ffmpeg)"}, + {BUF_VIDEO_FLI, CODEC_ID_FLIC, "FLIC Video (ffmpeg)"}, + {BUF_VIDEO_8BPS, CODEC_ID_8BPS, "Planar RGB (ffmpeg)"}, + {BUF_VIDEO_SMC, CODEC_ID_SMC, "Apple Quicktime Graphics/SMC (ffmpeg)"}, + {BUF_VIDEO_DUCKTM1, CODEC_ID_TRUEMOTION1,"Duck TrueMotion v1 (ffmpeg)"}, + {BUF_VIDEO_DUCKTM2, CODEC_ID_TRUEMOTION2,"Duck TrueMotion v2 (ffmpeg)"}, + {BUF_VIDEO_VMD, CODEC_ID_VMDVIDEO, "Sierra VMD Video (ffmpeg)"}, + {BUF_VIDEO_ZLIB, CODEC_ID_ZLIB, "ZLIB Video (ffmpeg)"}, + {BUF_VIDEO_MSZH, CODEC_ID_MSZH, "MSZH Video (ffmpeg)"}, + {BUF_VIDEO_ASV1, CODEC_ID_ASV1, "ASV v1 Video (ffmpeg)"}, + {BUF_VIDEO_ASV2, CODEC_ID_ASV2, "ASV v2 Video (ffmpeg)"}, + {BUF_VIDEO_ATIVCR1, CODEC_ID_VCR1, "ATI VCR-1 (ffmpeg)"}, + {BUF_VIDEO_FLV1, CODEC_ID_FLV1, "Flash Video (ffmpeg)"}, + {BUF_VIDEO_QTRLE, CODEC_ID_QTRLE, "Apple Quicktime Animation/RLE (ffmpeg)"}, + {BUF_VIDEO_H264, CODEC_ID_H264, "H.264/AVC (ffmpeg)"}, + {BUF_VIDEO_H261, CODEC_ID_H261, "H.261 (ffmpeg)"}, + {BUF_VIDEO_AASC, CODEC_ID_AASC, "Autodesk Video (ffmpeg)"}, + {BUF_VIDEO_LOCO, CODEC_ID_LOCO, "LOCO (ffmpeg)"}, + {BUF_VIDEO_QDRW, CODEC_ID_QDRAW, "QuickDraw (ffmpeg)"}, + {BUF_VIDEO_QPEG, CODEC_ID_QPEG, "Q-Team QPEG (ffmpeg)"}, + {BUF_VIDEO_TSCC, CODEC_ID_TSCC, "TechSmith Video (ffmpeg)"}, + {BUF_VIDEO_ULTI, CODEC_ID_ULTI, "IBM UltiMotion (ffmpeg)"}, + {BUF_VIDEO_WNV1, CODEC_ID_WNV1, "Winnow Video (ffmpeg)"}, + {BUF_VIDEO_XL, CODEC_ID_VIXL, "Miro/Pinnacle VideoXL (ffmpeg)"}, + {BUF_VIDEO_RT21, CODEC_ID_INDEO2, "Indeo/RealTime 2 (ffmpeg)"}, + {BUF_VIDEO_FPS1, CODEC_ID_FRAPS, "Fraps (ffmpeg)"}, + {BUF_VIDEO_MPEG, CODEC_ID_MPEG1VIDEO, "MPEG 1/2 (ffmpeg)"}, + {BUF_VIDEO_CSCD, CODEC_ID_CSCD, "CamStudio (ffmpeg)"}, + {BUF_VIDEO_AVS, CODEC_ID_AVS, "AVS (ffmpeg)"}, + {BUF_VIDEO_ALGMM, CODEC_ID_MMVIDEO, "American Laser Games MM (ffmpeg)"}, + {BUF_VIDEO_ZMBV, CODEC_ID_ZMBV, "Zip Motion Blocks Video (ffmpeg)"}, + {BUF_VIDEO_SMACKER, CODEC_ID_SMACKVIDEO, "Smacker (ffmpeg)"}, + {BUF_VIDEO_NUV, CODEC_ID_NUV, "NuppelVideo (ffmpeg)"}, + {BUF_VIDEO_KMVC, CODEC_ID_KMVC, "Karl Morton's Video Codec (ffmpeg)"}, + {BUF_VIDEO_FLASHSV, CODEC_ID_FLASHSV, "Flash Screen Video (ffmpeg)"}, + {BUF_VIDEO_CAVS, CODEC_ID_CAVS, "Chinese AVS (ffmpeg)"}, +}; + + +static void init_video_codec (ff_video_decoder_t *this, unsigned int codec_type) { + size_t i; + + /* find the decoder */ + this->codec = NULL; + + for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++) + if(ff_video_lookup[i].type == codec_type) { + pthread_mutex_lock(&ffmpeg_lock); + this->codec = avcodec_find_decoder(ff_video_lookup[i].id); + pthread_mutex_unlock(&ffmpeg_lock); + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, + ff_video_lookup[i].name); + break; + } + + if (!this->codec) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), + codec_type); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); + return; + } + + lprintf("lavc decoder found\n"); + + /* force (width % 8 == 0), otherwise there will be + * display problems with Xv. + */ + this->bih.biWidth = (this->bih.biWidth + 1) & (~1); + + this->context->width = this->bih.biWidth; + this->context->height = this->bih.biHeight; + this->context->stream_codec_tag = this->context->codec_tag = + _x_stream_info_get(this->stream, XINE_STREAM_INFO_VIDEO_FOURCC); + + + /* Some codecs (eg rv10) copy flags in init so it's necessary to set + * this flag here in case we are going to use direct rendering */ + if(this->codec->capabilities & CODEC_CAP_DR1) { + this->context->flags |= CODEC_FLAG_EMU_EDGE; + } + + pthread_mutex_lock(&ffmpeg_lock); + if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock(&ffmpeg_lock); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: couldn't open decoder\n")); + free(this->context); + this->context = NULL; + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); + return; + } + pthread_mutex_unlock(&ffmpeg_lock); + + lprintf("lavc decoder opened\n"); + + this->decoder_ok = 1; + + if ((codec_type != BUF_VIDEO_MPEG) && + (codec_type != BUF_VIDEO_DV)) { + + if (!this->bih.biWidth || !this->bih.biHeight) { + this->bih.biWidth = this->context->width; + this->bih.biHeight = this->context->height; + } + + + set_stream_info(this); + } + + this->stream->video_out->open (this->stream->video_out, this->stream); + + this->skipframes = 0; + + /* enable direct rendering by default */ + this->output_format = XINE_IMGFMT_YV12; +#ifdef ENABLE_DIRECT_RENDERING + if( this->codec->capabilities & CODEC_CAP_DR1 && this->codec->id != CODEC_ID_H264 ) { + this->context->get_buffer = get_buffer; + this->context->release_buffer = release_buffer; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: direct rendering enabled\n")); + } +#endif + + /* flag for interlaced streams */ + this->frame_flags = 0; + /* FIXME: which codecs can be interlaced? + FIXME: check interlaced DCT and other codec specific info. */ + switch( codec_type ) { + case BUF_VIDEO_DV: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_MPEG: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_MJPEG: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_HUFFYUV: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + } + +} + +static void pp_quality_cb(void *user_data, xine_cfg_entry_t *entry) { + ff_video_class_t *class = (ff_video_class_t *) user_data; + + class->pp_quality = entry->num_value; +} + +static void pp_change_quality (ff_video_decoder_t *this) { + this->pp_quality = this->class->pp_quality; + + if(this->pp_available && this->pp_quality) { + if(!this->pp_context && this->context) + this->pp_context = pp_get_context(this->context->width, this->context->height, + this->pp_flags); + if(this->pp_mode) + pp_free_mode(this->pp_mode); + + this->pp_mode = pp_get_mode_by_name_and_quality("hb:a,vb:a,dr:a", + this->pp_quality); + } else { + if(this->pp_mode) { + pp_free_mode(this->pp_mode); + this->pp_mode = NULL; + } + + if(this->pp_context) { + pp_free_context(this->pp_context); + this->pp_context = NULL; + } + } +} + +static void init_postprocess (ff_video_decoder_t *this) { + uint32_t cpu_caps; + + /* Allow post processing on mpeg-4 (based) codecs */ + switch(this->codec->id) { + case CODEC_ID_MPEG4: + case CODEC_ID_MSMPEG4V1: + case CODEC_ID_MSMPEG4V2: + case CODEC_ID_MSMPEG4V3: + case CODEC_ID_WMV1: + case CODEC_ID_WMV2: + this->pp_available = 1; + break; + default: + this->pp_available = 0; + break; + } + + /* Detect what cpu accel we have */ + cpu_caps = xine_mm_accel(); + this->pp_flags = PP_FORMAT_420; + + if(cpu_caps & MM_ACCEL_X86_MMX) + this->pp_flags |= PP_CPU_CAPS_MMX; + + if(cpu_caps & MM_ACCEL_X86_MMXEXT) + this->pp_flags |= PP_CPU_CAPS_MMX2; + + if(cpu_caps & MM_ACCEL_X86_3DNOW) + this->pp_flags |= PP_CPU_CAPS_3DNOW; + + /* Set level */ + pp_change_quality(this); +} + +static int ff_handle_mpeg_sequence(ff_video_decoder_t *this, mpeg_parser_t *parser) { + + /* + * init codec + */ + if (this->decoder_init_mode) { + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, + "mpeg-1 (ffmpeg)"); + + init_video_codec (this, BUF_VIDEO_MPEG); + this->decoder_init_mode = 0; + } + + /* frame format change */ + if ((parser->width != this->bih.biWidth) || + (parser->height != this->bih.biHeight) || + (parser->frame_aspect_ratio != this->aspect_ratio)) { + xine_event_t event; + xine_format_change_data_t data; + + this->bih.biWidth = parser->width; + this->bih.biHeight = parser->height; + this->aspect_ratio = parser->frame_aspect_ratio; + this->aspect_ratio_prio = 2; + lprintf("mpeg seq aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + + event.type = XINE_EVENT_FRAME_FORMAT_CHANGE; + event.stream = this->stream; + event.data = &data; + event.data_length = sizeof(data); + data.width = this->bih.biWidth; + data.height = this->bih.biHeight; + data.aspect = this->aspect_ratio; + data.pan_scan = 0; + xine_event_send(this->stream, &event); + } + this->video_step = this->mpeg_parser->frame_duration; + + return 1; +} + +static void ff_convert_frame(ff_video_decoder_t *this, vo_frame_t *img) { + int y; + uint8_t *dy, *du, *dv, *sy, *su, *sv; + + dy = img->base[0]; + du = img->base[1]; + dv = img->base[2]; + sy = this->av_frame->data[0]; + su = this->av_frame->data[1]; + sv = this->av_frame->data[2]; + + if (this->context->pix_fmt == PIX_FMT_YUV410P) { + + yuv9_to_yv12( + /* Y */ + this->av_frame->data[0], + this->av_frame->linesize[0], + img->base[0], + img->pitches[0], + /* U */ + this->av_frame->data[1], + this->av_frame->linesize[1], + img->base[1], + img->pitches[1], + /* V */ + this->av_frame->data[2], + this->av_frame->linesize[2], + img->base[2], + img->pitches[2], + /* width x height */ + img->width, + img->height); + + } else if (this->context->pix_fmt == PIX_FMT_YUV411P) { + + yuv411_to_yv12( + /* Y */ + this->av_frame->data[0], + this->av_frame->linesize[0], + img->base[0], + img->pitches[0], + /* U */ + this->av_frame->data[1], + this->av_frame->linesize[1], + img->base[1], + img->pitches[1], + /* V */ + this->av_frame->data[2], + this->av_frame->linesize[2], + img->base[2], + img->pitches[2], + /* width x height */ + img->width, + img->height); + + } else if (this->context->pix_fmt == PIX_FMT_RGBA32) { + + int x, plane_ptr = 0; + uint32_t *argb_pixels; + uint32_t argb; + + for(y = 0; y < img->height; y++) { + argb_pixels = (uint32_t *)sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + /* this is endian-safe as the ARGB pixels are stored in + * machine order */ + argb = *argb_pixels++; + r = (argb >> 16) & 0xFF; + g = (argb >> 8) & 0xFF; + b = (argb >> 0) & 0xFF; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_RGB565) { + + int x, plane_ptr = 0; + uint8_t *src; + uint16_t pixel16; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + /* a 16-bit RGB565 pixel is supposed to be stored in native-endian + * byte order; the following should be endian-safe */ + pixel16 = *((uint16_t *)src); + src += 2; + b = (pixel16 << 3) & 0xFF; + g = (pixel16 >> 3) & 0xFF; + r = (pixel16 >> 8) & 0xFF; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_RGB555) { + + int x, plane_ptr = 0; + uint8_t *src; + uint16_t pixel16; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + /* a 16-bit RGB555 pixel is supposed to be stored in native-endian + * byte order; the following should be endian-safe */ + pixel16 = *((uint16_t *)src); + src += 2; + b = (pixel16 << 3) & 0xFF; + g = (pixel16 >> 2) & 0xFF; + r = (pixel16 >> 7) & 0xFF; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_BGR24) { + + int x, plane_ptr = 0; + uint8_t *src; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + b = *src++; + g = *src++; + r = *src++; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_RGB24) { + + int x, plane_ptr = 0; + uint8_t *src; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + r = *src++; + g = *src++; + b = *src++; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_PAL8) { + + int x, plane_ptr = 0; + uint8_t *src; + uint8_t pixel; + uint32_t *palette32 = (uint32_t *)su; /* palette is in data[1] */ + uint32_t rgb_color; + uint8_t r, g, b; + uint8_t y_palette[256]; + uint8_t u_palette[256]; + uint8_t v_palette[256]; + + for (x = 0; x < 256; x++) { + rgb_color = palette32[x]; + b = rgb_color & 0xFF; + rgb_color >>= 8; + g = rgb_color & 0xFF; + rgb_color >>= 8; + r = rgb_color & 0xFF; + y_palette[x] = COMPUTE_Y(r, g, b); + u_palette[x] = COMPUTE_U(r, g, b); + v_palette[x] = COMPUTE_V(r, g, b); + } + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + pixel = *src++; + + this->yuv.y[plane_ptr] = y_palette[pixel]; + this->yuv.u[plane_ptr] = u_palette[pixel]; + this->yuv.v[plane_ptr] = v_palette[pixel]; + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else { + + for (y=0; yheight; y++) { + xine_fast_memcpy (dy, sy, img->width); + + dy += img->pitches[0]; + + sy += this->av_frame->linesize[0]; + } + + for (y=0; y<(img->height/2); y++) { + + if (this->context->pix_fmt != PIX_FMT_YUV444P) { + + xine_fast_memcpy (du, su, img->width/2); + xine_fast_memcpy (dv, sv, img->width/2); + + } else { + + int x; + uint8_t *src; + uint8_t *dst; + + /* subsample */ + + src = su; dst = du; + for (x=0; x<(img->width/2); x++) { + *dst = *src; + dst++; + src += 2; + } + src = sv; dst = dv; + for (x=0; x<(img->width/2); x++) { + *dst = *src; + dst++; + src += 2; + } + + } + + du += img->pitches[1]; + dv += img->pitches[2]; + + if (this->context->pix_fmt != PIX_FMT_YUV420P) { + su += 2*this->av_frame->linesize[1]; + sv += 2*this->av_frame->linesize[2]; + } else { + su += this->av_frame->linesize[1]; + sv += this->av_frame->linesize[2]; + } + } + } +} + +static void ff_check_bufsize (ff_video_decoder_t *this, int size) { + if (size > this->bufsize) { + this->bufsize = size + size / 2; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc(this->buf, this->bufsize + FF_INPUT_BUFFER_PADDING_SIZE ); + } +} + +static void ff_handle_preview_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + int codec_type; + + lprintf ("preview buffer\n"); + + codec_type = buf->type & 0xFFFF0000; + if (codec_type == BUF_VIDEO_MPEG) { + this->is_mpeg12 = 1; + if ( this->mpeg_parser == NULL ) { + this->mpeg_parser = xine_xmalloc(sizeof(mpeg_parser_t)); + mpeg_parser_init(this->mpeg_parser); + this->decoder_init_mode = 0; + } + } + + if (this->decoder_init_mode && !this->is_mpeg12) { + init_video_codec(this, codec_type); + init_postprocess(this); + this->decoder_init_mode = 0; + } +} + +static void ff_handle_header_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + + lprintf ("header buffer\n"); + + /* accumulate data */ + ff_check_bufsize(this, this->size + buf->size); + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + int codec_type; + + lprintf ("header complete\n"); + codec_type = buf->type & 0xFFFF0000; + + if (buf->decoder_flags & BUF_FLAG_STDHEADER) { + + lprintf("standard header\n"); + + /* init package containing bih */ + memcpy ( &this->bih, this->buf, sizeof(xine_bmiheader) ); + + if (this->bih.biSize > sizeof(xine_bmiheader)) { + this->context->extradata_size = this->bih.biSize - sizeof(xine_bmiheader); + this->context->extradata = malloc(this->context->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, this->buf + sizeof(xine_bmiheader), + this->context->extradata_size); + } + + this->context->bits_per_sample = this->bih.biBitCount; + + } else { + + switch (codec_type) { + case BUF_VIDEO_RV10: + case BUF_VIDEO_RV20: + this->bih.biWidth = BE_16(&this->buf[12]); + this->bih.biHeight = BE_16(&this->buf[14]); + + this->context->sub_id = BE_32(&this->buf[30]); + + this->context->slice_offset = xine_xmalloc(sizeof(int)*SLICE_OFFSET_SIZE); + this->slice_offset_size = SLICE_OFFSET_SIZE; + + lprintf("w=%d, h=%d\n", this->bih.biWidth, this->bih.biHeight); + + break; + default: + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_video_dec: unknown header for buf type 0x%X\n", codec_type); + return; + } + } + + /* reset accumulator */ + this->size = 0; + } +} + +static void ff_handle_special_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + /* take care of all the various types of special buffers + * note that order is important here */ + lprintf("special buffer\n"); + + if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM && + !this->context->extradata_size) { + + lprintf("BUF_SPECIAL_STSD_ATOM\n"); + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = xine_xmalloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + + } else if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG && + !this->context->extradata_size) { + + lprintf("BUF_SPECIAL_DECODER_CONFIG\n"); + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = xine_xmalloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + + } else if (buf->decoder_info[1] == BUF_SPECIAL_PALETTE) { + unsigned int i; + + palette_entry_t *demuxer_palette; + AVPaletteControl *decoder_palette; + + lprintf("BUF_SPECIAL_PALETTE\n"); + this->context->palctrl = &this->palette_control; + decoder_palette = (AVPaletteControl *)this->context->palctrl; + demuxer_palette = (palette_entry_t *)buf->decoder_info_ptr[2]; + + for (i = 0; i < buf->decoder_info[2]; i++) { + decoder_palette->palette[i] = + (demuxer_palette[i].r << 16) | + (demuxer_palette[i].g << 8) | + (demuxer_palette[i].b << 0); + } + decoder_palette->palette_changed = 1; + + } else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) { + int i; + + lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n"); + this->context->slice_count = buf->decoder_info[2]+1; + + lprintf("slice_count=%d\n", this->context->slice_count); + + if(this->context->slice_count > this->slice_offset_size) { + this->context->slice_offset = realloc(this->context->slice_offset, + sizeof(int)*this->context->slice_count); + this->slice_offset_size = this->context->slice_count; + } + + for(i = 0; i < this->context->slice_count; i++) { + this->context->slice_offset[i] = + ((uint32_t *) buf->decoder_info_ptr[2])[(2*i)+1]; + lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]); + } + } +} + +static void ff_handle_mpeg12_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + + vo_frame_t *img; + int free_img; + int got_picture, len; + int offset = 0; + int flush = 0; + int size = buf->size; + + lprintf("handle_mpeg12_buffer\n"); + + while ((size > 0) || (flush == 1)) { + + uint8_t *current; + int next_flush; + + got_picture = 0; + if (!flush) { + current = mpeg_parser_decode_data(this->mpeg_parser, + buf->content + offset, buf->content + offset + size, + &next_flush); + } else { + current = buf->content + offset + size; /* end of the buffer */ + next_flush = 0; + } + if (current == NULL) { + lprintf("current == NULL\n"); + return; + } + + if (this->mpeg_parser->has_sequence) { + ff_handle_mpeg_sequence(this, this->mpeg_parser); + } + + if (!this->decoder_ok) + return; + + if (flush) { + lprintf("flush lavc buffers\n"); + /* hack: ffmpeg outputs the last frame if size=0 */ + this->mpeg_parser->buffer_size = 0; + } + + /* skip decoding b frames if too late */ + this->context->hurry_up = (this->skipframes > 0); + + lprintf("avcodec_decode_video: size=%d\n", this->mpeg_parser->buffer_size); + len = avcodec_decode_video (this->context, this->av_frame, + &got_picture, this->mpeg_parser->chunk_buffer, + this->mpeg_parser->buffer_size); + lprintf("avcodec_decode_video: decoded_size=%d, got_picture=%d\n", + len, got_picture); + len = current - buf->content - offset; + lprintf("avcodec_decode_video: consumed_size=%d\n", len); + + flush = next_flush; + + if ((len < 0) || (len > buf->size)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_video_dec: error decompressing frame\n"); + size = 0; /* draw a bad frame and exit */ + } else { + size -= len; + offset += len; + } + + if (got_picture && this->av_frame->data[0]) { + /* got a picture, draw it */ + if(!this->av_frame->opaque) { + /* indirect rendering */ + img = this->stream->video_out->get_frame (this->stream->video_out, + this->bih.biWidth, + this->bih.biHeight, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + free_img = 1; + } else { + /* DR1 */ + img = (vo_frame_t*) this->av_frame->opaque; + free_img = 0; + } + + img->pts = this->pts; + this->pts = 0; + + if (this->av_frame->repeat_pict) + img->duration = this->video_step * 3 / 2; + else + img->duration = this->video_step; + + img->crop_right = this->crop_right; + img->crop_bottom = this->crop_bottom; + + this->skipframes = img->draw(img, this->stream); + + if(free_img) + img->free(img); + + } else { + + if (this->context->hurry_up) { + /* skipped frame, output a bad frame */ + img = this->stream->video_out->get_frame (this->stream->video_out, + this->bih.biWidth, + this->bih.biHeight, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + img->pts = 0; + img->duration = this->video_step; + img->bad_frame = 1; + this->skipframes = img->draw(img, this->stream); + img->free(img); + } + } + } +} + +static void ff_handle_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + uint8_t *chunk_buf = this->buf; + AVRational avr00 = {0, 1}; + + lprintf("handle_buffer\n"); + + if (!this->decoder_ok) { + if (this->decoder_init_mode) { + int codec_type = buf->type & 0xFFFF0000; + + /* init ffmpeg decoder */ + init_video_codec(this, codec_type); + init_postprocess(this); + this->decoder_init_mode = 0; + } else { + return; + } + } + + if (buf->decoder_flags & BUF_FLAG_FRAME_START) { + lprintf("BUF_FLAG_FRAME_START\n"); + this->size = 0; + } + + /* data accumulation */ + if (buf->size > 0) { + if ((this->size == 0) && + ((buf->size + FF_INPUT_BUFFER_PADDING_SIZE) < buf->max_size) && + (buf->decoder_flags & BUF_FLAG_FRAME_END)) { + /* buf contains a complete frame */ + /* no memcpy needed */ + chunk_buf = buf->content; + this->size = buf->size; + lprintf("no memcpy needed to accumulate data\n"); + } else { + /* copy data into our internal buffer */ + ff_check_bufsize(this, this->size + buf->size); + chunk_buf = this->buf; /* ff_check_bufsize might realloc this->buf */ + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + + this->size += buf->size; + lprintf("accumulate data into this->buf\n"); + } + } + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + + vo_frame_t *img; + int free_img; + int got_picture, len; + int got_one_picture = 0; + int offset = 0; + int codec_type = buf->type & 0xFFFF0000; + + /* pad input data */ + /* note: bitstream, alt bitstream reader or something will cause + * severe mpeg4 artifacts if padding is less than 32 bits. + */ + memset(&chunk_buf[this->size], 0, FF_INPUT_BUFFER_PADDING_SIZE); + + while (this->size > 0) { + + /* DV frames can be completely skipped */ + if( codec_type == BUF_VIDEO_DV && this->skipframes ) { + this->size = 0; + got_picture = 0; + } else { + /* skip decoding b frames if too late */ + this->context->hurry_up = (this->skipframes > 0); + + lprintf("buffer size: %d\n", this->size); + len = avcodec_decode_video (this->context, this->av_frame, + &got_picture, &chunk_buf[offset], + this->size); + lprintf("consumed size: %d, got_picture: %d\n", len, got_picture); + if ((len <= 0) || (len > this->size)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_video_dec: error decompressing frame\n"); + this->size = 0; + + } else { + + offset += len; + this->size -= len; + + if (this->size > 0) { + ff_check_bufsize(this, this->size); + memmove (this->buf, &chunk_buf[offset], this->size); + chunk_buf = this->buf; + } + } + } + + /* aspect ratio provided by ffmpeg, override previous setting */ + if ((this->aspect_ratio_prio < 2) && + av_cmp_q(this->context->sample_aspect_ratio, avr00)) { + + this->aspect_ratio = av_q2d(this->context->sample_aspect_ratio) * + (double)this->bih.biWidth / (double)this->bih.biHeight; + this->aspect_ratio_prio = 2; + lprintf("ffmpeg aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + + if (got_picture && this->av_frame->data[0]) { + /* got a picture, draw it */ + got_one_picture = 1; + if(!this->av_frame->opaque) { + /* indirect rendering */ + + /* initialize the colorspace converter */ + if (!this->cs_convert_init) { + if ((this->context->pix_fmt == PIX_FMT_RGBA32) || + (this->context->pix_fmt == PIX_FMT_RGB565) || + (this->context->pix_fmt == PIX_FMT_RGB555) || + (this->context->pix_fmt == PIX_FMT_BGR24) || + (this->context->pix_fmt == PIX_FMT_RGB24) || + (this->context->pix_fmt == PIX_FMT_PAL8)) { + this->output_format = XINE_IMGFMT_YUY2; + init_yuv_planes(&this->yuv, this->bih.biWidth, this->bih.biHeight); + this->yuv_init = 1; + } + this->cs_convert_init = 1; + } + + if (this->aspect_ratio_prio == 0) { + this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight; + this->aspect_ratio_prio = 1; + lprintf("default aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + + img = this->stream->video_out->get_frame (this->stream->video_out, + this->bih.biWidth, + this->bih.biHeight, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + free_img = 1; + } else { + /* DR1 */ + img = (vo_frame_t*) this->av_frame->opaque; + free_img = 0; + } + + /* post processing */ + if(this->pp_quality != this->class->pp_quality) + pp_change_quality(this); + + if(this->pp_available && this->pp_quality) { + + if(this->av_frame->opaque) { + /* DR1 */ + img = this->stream->video_out->get_frame (this->stream->video_out, + img->width, + img->height, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + free_img = 1; + } + + pp_postprocess(this->av_frame->data, this->av_frame->linesize, + img->base, img->pitches, + img->width, img->height, + this->av_frame->qscale_table, this->av_frame->qstride, + this->pp_mode, this->pp_context, + this->av_frame->pict_type); + + } else if (!this->av_frame->opaque) { + /* colorspace conversion or copy */ + ff_convert_frame(this, img); + } + + img->pts = this->pts; + this->pts = 0; + + /* workaround for weird 120fps streams */ + if( this->video_step == 750 ) { + /* fallback to the VIDEO_PTS_MODE */ + this->video_step = 0; + } + + if (this->av_frame->repeat_pict) + img->duration = this->video_step * 3 / 2; + else + img->duration = this->video_step; + + img->crop_right = this->crop_right; + img->crop_bottom = this->crop_bottom; + + this->skipframes = img->draw(img, this->stream); + + if(free_img) + img->free(img); + } + } + + if (!got_one_picture) { + /* skipped frame, output a bad frame */ + img = this->stream->video_out->get_frame (this->stream->video_out, + this->bih.biWidth, + this->bih.biHeight, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + img->pts = 0; + img->duration = this->video_step; + img->bad_frame = 1; + this->skipframes = img->draw(img, this->stream); + img->free(img); + } + } +} + +static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("processing packet type = %08x, len = %d, decoder_flags=%08x\n", + buf->type, buf->size, buf->decoder_flags); + + if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { + this->video_step = buf->decoder_info[0]; + _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); + } + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) { + + ff_handle_preview_buffer(this, buf); + + } else { + + if (buf->decoder_flags & BUF_FLAG_SPECIAL) { + + ff_handle_special_buffer(this, buf); + + } + + if (buf->decoder_flags & BUF_FLAG_HEADER) { + + ff_handle_header_buffer(this, buf); + + if (buf->decoder_flags & BUF_FLAG_ASPECT) { + if (this->aspect_ratio_prio < 3) { + this->aspect_ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2]; + this->aspect_ratio_prio = 3; + lprintf("aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + } + + } else { + + /* decode */ + if (buf->pts) + this->pts = buf->pts; + + if (this->is_mpeg12) { + ff_handle_mpeg12_buffer(this, buf); + } else { + ff_handle_buffer(this, buf); + } + + } + } +} + +static void ff_flush (video_decoder_t *this_gen) { + lprintf ("ff_flush\n"); +} + +static void ff_reset (video_decoder_t *this_gen) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("ff_reset\n"); + + this->size = 0; + + if(this->context && this->decoder_ok) + avcodec_flush_buffers(this->context); + + if (this->is_mpeg12) + mpeg_parser_reset(this->mpeg_parser); +} + +static void ff_discontinuity (video_decoder_t *this_gen) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("ff_discontinuity\n"); + this->pts = 0; +} + +static void ff_dispose (video_decoder_t *this_gen) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("ff_dispose\n"); + + if (this->decoder_ok) { + xine_list_iterator_t it; + AVFrame *av_frame; + + pthread_mutex_lock(&ffmpeg_lock); + avcodec_close (this->context); + pthread_mutex_unlock(&ffmpeg_lock); + + /* frame garbage collector here - workaround for buggy ffmpeg codecs that + * don't release their DR1 frames */ + while( (it = xine_list_front(this->dr1_frames)) != NULL ) + { + av_frame = (AVFrame *)xine_list_get_value(this->dr1_frames, it); + release_buffer(this->context, av_frame); + } + + this->stream->video_out->close(this->stream->video_out, this->stream); + this->decoder_ok = 0; + } + + if(this->context && this->context->slice_offset) + free(this->context->slice_offset); + + if(this->context && this->context->extradata) + free(this->context->extradata); + + if(this->yuv_init) + free_yuv_planes(&this->yuv); + + if( this->context ) + free( this->context ); + + if( this->av_frame ) + free( this->av_frame ); + + if (this->buf) + free(this->buf); + this->buf = NULL; + + if(this->pp_context) + pp_free_context(this->pp_context); + + if(this->pp_mode) + pp_free_mode(this->pp_mode); + + mpeg_parser_dispose(this->mpeg_parser); + + xine_list_delete(this->dr1_frames); + + free (this_gen); +} + +static video_decoder_t *ff_video_open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { + + ff_video_decoder_t *this ; + + lprintf ("open_plugin\n"); + + this = (ff_video_decoder_t *) xine_xmalloc (sizeof (ff_video_decoder_t)); + + this->video_decoder.decode_data = ff_decode_data; + this->video_decoder.flush = ff_flush; + this->video_decoder.reset = ff_reset; + this->video_decoder.discontinuity = ff_discontinuity; + this->video_decoder.dispose = ff_dispose; + this->size = 0; + + this->stream = stream; + this->class = (ff_video_class_t *) class_gen; + + this->av_frame = avcodec_alloc_frame(); + this->context = avcodec_alloc_context(); + this->context->opaque = this; + this->context->palctrl = NULL; + + this->decoder_ok = 0; + this->decoder_init_mode = 1; + this->buf = xine_xmalloc(VIDEOBUFSIZE + FF_INPUT_BUFFER_PADDING_SIZE); + this->bufsize = VIDEOBUFSIZE; + + this->is_mpeg12 = 0; + this->aspect_ratio = 0; + + this->pp_quality = 0; + this->pp_context = NULL; + this->pp_mode = NULL; + + this->mpeg_parser = NULL; + + this->dr1_frames = xine_list_new(); + + return &this->video_decoder; +} + +static char *ff_video_get_identifier (video_decoder_class_t *this) { + return "ffmpeg video"; +} + +static char *ff_video_get_description (video_decoder_class_t *this) { + return "ffmpeg based video decoder plugin"; +} + +static void ff_video_dispose_class (video_decoder_class_t *this) { + free (this); +} + +void *init_video_plugin (xine_t *xine, void *data) { + + ff_video_class_t *this; + config_values_t *config; + + this = (ff_video_class_t *) xine_xmalloc (sizeof (ff_video_class_t)); + + this->decoder_class.open_plugin = ff_video_open_plugin; + this->decoder_class.get_identifier = ff_video_get_identifier; + this->decoder_class.get_description = ff_video_get_description; + this->decoder_class.dispose = ff_video_dispose_class; + this->xine = xine; + + pthread_once( &once_control, init_once_routine ); + + /* Configuration for post processing quality - default to mid (3) for the + * moment */ + config = xine->config; + + this->pp_quality = xine->config->register_range(config, "video.processing.ffmpeg_pp_quality", 3, + 0, PP_QUALITY_MAX, + _("MPEG-4 postprocessing quality"), + _("You can adjust the amount of post processing applied to MPEG-4 video.\n" + "Higher values result in better quality, but need more CPU. Lower values may " + "result in image defects like block artifacts. For high quality content, " + "too heavy post processing can actually make the image worse by blurring it " + "too much."), + 10, pp_quality_cb, this); + + return this; +} + +static uint32_t supported_video_types[] = { + #ifdef CONFIG_MSMPEG4V1_DECODER + BUF_VIDEO_MSMPEG4_V1, + #endif + #ifdef CONFIG_MSMPEG4V2_DECODER + BUF_VIDEO_MSMPEG4_V2, + #endif + #ifdef CONFIG_MSMPEG4V3_DECODER + BUF_VIDEO_MSMPEG4_V3, + #endif + #ifdef CONFIG_WMV1_DECODER + BUF_VIDEO_WMV7, + #endif + #ifdef CONFIG_WMV2_DECODER + BUF_VIDEO_WMV8, + #endif + #ifdef CONFIG_WMV3_DECODER + BUF_VIDEO_WMV9, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_MPEG4, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_XVID, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_DIVX5, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_3IVX, + #endif + #ifdef CONFIG_MJPEG_DECODER + BUF_VIDEO_JPEG, + #endif + #ifdef CONFIG_MJPEG_DECODER + BUF_VIDEO_MJPEG, + #endif + #ifdef CONFIG_MJPEGB_DECODER + BUF_VIDEO_MJPEG_B, + #endif + #ifdef CONFIG_H263I_DECODER + BUF_VIDEO_I263, + #endif + #ifdef CONFIG_H263_DECODER + BUF_VIDEO_H263, + #endif + #ifdef CONFIG_RV10_DECODER + BUF_VIDEO_RV10, + #endif + #ifdef CONFIG_RV20_DECODER + BUF_VIDEO_RV20, + #endif + #ifdef CONFIG_INDEO3_DECODER + BUF_VIDEO_IV31, + #endif + #ifdef CONFIG_INDEO3_DECODER + BUF_VIDEO_IV32, + #endif + #ifdef CONFIG_SVQ1_DECODER + BUF_VIDEO_SORENSON_V1, + #endif + #ifdef CONFIG_SVQ3_DECODER + BUF_VIDEO_SORENSON_V3, + #endif + #ifdef CONFIG_DVVIDEO_DECODER + BUF_VIDEO_DV, + #endif + #ifdef CONFIG_HUFFYUV_DECODER + BUF_VIDEO_HUFFYUV, + #endif + #ifdef CONFIG_VP3_DECODER + BUF_VIDEO_VP31, + #endif + #ifdef CONFIG_VP5_DECODER + BUF_VIDEO_VP5, + #endif + #ifdef CONFIG_VP6_DECODER + BUF_VIDEO_VP6, + BUF_VIDEO_VP6F, + #endif + #ifdef CONFIG_4XM_DECODER + BUF_VIDEO_4XM, + #endif + #ifdef CONFIG_CINEPAK_DECODER + BUF_VIDEO_CINEPAK, + #endif + #ifdef CONFIG_MSVIDEO1_DECODER + BUF_VIDEO_MSVC, + #endif + #ifdef CONFIG_MSRLE_DECODER + BUF_VIDEO_MSRLE, + #endif + #ifdef CONFIG_RPZA_DECODER + BUF_VIDEO_RPZA, + #endif + #ifdef CONFIG_CYUV_DECODER + BUF_VIDEO_CYUV, + #endif + #ifdef CONFIG_ROQ_DECODER + BUF_VIDEO_ROQ, + #endif + #ifdef CONFIG_IDCIN_DECODER + BUF_VIDEO_IDCIN, + #endif + #ifdef CONFIG_XAN_WC3_DECODER + BUF_VIDEO_WC3, + #endif + #ifdef CONFIG_WS_VQA_DECODER + BUF_VIDEO_VQA, + #endif + #ifdef CONFIG_INTERPLAY_VIDEO_DECODER + BUF_VIDEO_INTERPLAY, + #endif + #ifdef CONFIG_FLIC_DECODER + BUF_VIDEO_FLI, + #endif + #ifdef CONFIG_8BPS_DECODER + BUF_VIDEO_8BPS, + #endif + #ifdef CONFIG_SMC_DECODER + BUF_VIDEO_SMC, + #endif + #ifdef CONFIG_TRUEMOTION1_DECODER + BUF_VIDEO_DUCKTM1, + #endif + #ifdef CONFIG_TRUEMOTION2_DECODER + BUF_VIDEO_DUCKTM2, + #endif + #ifdef CONFIG_VMDVIDEO_DECODER + BUF_VIDEO_VMD, + #endif + #ifdef CONFIG_ZLIB_DECODER + BUF_VIDEO_ZLIB, + #endif + #ifdef CONFIG_MSZH_DECODER + BUF_VIDEO_MSZH, + #endif + #ifdef CONFIG_ASV1_DECODER + BUF_VIDEO_ASV1, + #endif + #ifdef CONFIG_ASV2_DECODER + BUF_VIDEO_ASV2, + #endif + #ifdef CONFIG_VCR1_DECODER + BUF_VIDEO_ATIVCR1, + #endif + #ifdef CONFIG_FLV_DECODER + BUF_VIDEO_FLV1, + #endif + #ifdef CONFIG_QTRLE_DECODER + BUF_VIDEO_QTRLE, + #endif + #ifdef CONFIG_H264_DECODER + BUF_VIDEO_H264, + #endif + #ifdef CONFIG_H261_DECODER + BUF_VIDEO_H261, + #endif + #ifdef CONFIG_AASC_DECODER + BUF_VIDEO_AASC, + #endif + #ifdef CONFIG_LOCO_DECODER + BUF_VIDEO_LOCO, + #endif + #ifdef CONFIG_QDRAW_DECODER + BUF_VIDEO_QDRW, + #endif + #ifdef CONFIG_QPEG_DECODER + BUF_VIDEO_QPEG, + #endif + #ifdef CONFIG_TSCC_DECODER + BUF_VIDEO_TSCC, + #endif + #ifdef CONFIG_ULTI_DECODER + BUF_VIDEO_ULTI, + #endif + #ifdef CONFIG_WNV1_DECODER + BUF_VIDEO_WNV1, + #endif + #ifdef CONFIG_VIXL_DECODER + BUF_VIDEO_XL, + #endif + #ifdef CONFIG_INDEO2_DECODER + BUF_VIDEO_RT21, + #endif + #ifdef CONFIG_FRAPS_DECODER + BUF_VIDEO_FPS1, + #endif + #ifdef CONFIG_MPEG1VIDEO_DECODER + BUF_VIDEO_MPEG, + #endif + #ifdef CONFIG_CSCD_DECODER + BUF_VIDEO_CSCD, + #endif + #ifdef CONFIG_AVS_DECODER + BUF_VIDEO_AVS, + #endif + #ifdef CONFIG_MMVIDEO_DECODER + BUF_VIDEO_ALGMM, + #endif + #ifdef CONFIG_ZMBV_DECODER + BUF_VIDEO_ZMBV, + #endif + #ifdef CONFIG_SMACKVIDEO_DECODER + BUF_VIDEO_SMACKER, + #endif + #ifdef CONFIG_NUV_DECODER + BUF_VIDEO_NUV, + #endif + #ifdef CONFIG_KMVC_DECODER + BUF_VIDEO_KMVC, + #endif + #ifdef CONFIG_FLASHSV_DECODER + BUF_VIDEO_FLASHSV, + #endif + #ifdef CONFIG_CAVS_DECODER + BUF_VIDEO_CAVS, + #endif + + 0 +}; + +static uint32_t wmv8_video_types[] = { + BUF_VIDEO_WMV8, + 0 +}; + +static uint32_t wmv9_video_types[] = { + BUF_VIDEO_WMV9, + 0 +}; + +decoder_info_t dec_info_ffmpeg_video = { + supported_video_types, /* supported types */ + 6 /* priority */ +}; + +decoder_info_t dec_info_ffmpeg_wmv8 = { + wmv8_video_types, /* supported types */ + 0 /* priority */ +}; + +decoder_info_t dec_info_ffmpeg_wmv9 = { + wmv9_video_types, /* supported types */ + 0 /* priority */ +}; diff --git a/src/libffmpeg/ffmpeg_decoder.c b/src/libffmpeg/ffmpeg_decoder.c new file mode 100644 index 000000000..6f85cc1fa --- /dev/null +++ b/src/libffmpeg/ffmpeg_decoder.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2001-2004 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.173 2007/01/13 21:19:52 miguelfreitas Exp $ + * + * xine decoder plugin using ffmpeg + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "ffmpeg_config.h" +#endif + +#include "xine_internal.h" + +#include "ffmpeg_decoder.h" + +/* + * common initialisation + */ + +pthread_once_t once_control = PTHREAD_ONCE_INIT; +pthread_mutex_t ffmpeg_lock; + +#ifndef HAVE_FFMPEG + +#define REGISTER_ENCODER(X,x) \ + if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder) +#define REGISTER_DECODER(X,x) \ + if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder) +#define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x) + +#define REGISTER_PARSER(X,x) \ + if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser) + +/* If you do not call this function, then you can select exactly which + formats you want to support */ + +/** + * simple call to register all the codecs. + */ +void avcodec_register_all(void) +{ + static int inited = 0; + + if (inited != 0) + return; + inited = 1; + + /* video codecs */ + REGISTER_DECODER(AASC, aasc); + REGISTER_ENCDEC (ASV1, asv1); + REGISTER_ENCDEC (ASV2, asv2); + REGISTER_DECODER(AVS, avs); + REGISTER_DECODER(BMP, bmp); + REGISTER_DECODER(CAVS, cavs); + REGISTER_DECODER(CINEPAK, cinepak); + REGISTER_DECODER(CLJR, cljr); + REGISTER_DECODER(CSCD, cscd); + REGISTER_DECODER(CYUV, cyuv); + REGISTER_DECODER(DSICINVIDEO, dsicinvideo); + REGISTER_ENCDEC (DVVIDEO, dvvideo); + REGISTER_DECODER(EIGHTBPS, eightbps); + REGISTER_ENCDEC (FFV1, ffv1); + REGISTER_ENCDEC (FFVHUFF, ffvhuff); + REGISTER_DECODER(FLASHSV, flashsv); + REGISTER_DECODER(FLIC, flic); + REGISTER_ENCDEC (FLV, flv); + REGISTER_DECODER(FOURXM, fourxm); + REGISTER_DECODER(FRAPS, fraps); + REGISTER_ENCDEC (GIF, gif); + REGISTER_ENCDEC (H261, h261); + REGISTER_ENCDEC (H263, h263); + REGISTER_DECODER(H263I, h263i); + REGISTER_ENCODER(H263P, h263p); + REGISTER_DECODER(H264, h264); + REGISTER_ENCDEC (HUFFYUV, huffyuv); + REGISTER_DECODER(IDCIN, idcin); + REGISTER_DECODER(INDEO2, indeo2); + REGISTER_DECODER(INDEO3, indeo3); + REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video); + REGISTER_ENCODER(JPEGLS, jpegls); + REGISTER_DECODER(KMVC, kmvc); + REGISTER_ENCODER(LJPEG, ljpeg); + REGISTER_DECODER(LOCO, loco); + REGISTER_DECODER(MDEC, mdec); + REGISTER_ENCDEC (MJPEG, mjpeg); + REGISTER_DECODER(MJPEGB, mjpegb); + REGISTER_DECODER(MMVIDEO, mmvideo); +#ifdef HAVE_XVMC + REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc); +#endif + REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); + REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); + REGISTER_ENCDEC (MPEG4, mpeg4); + REGISTER_DECODER(MPEGVIDEO, mpegvideo); + REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); + REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); + REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); + REGISTER_DECODER(MSRLE, msrle); + REGISTER_DECODER(MSVIDEO1, msvideo1); + REGISTER_DECODER(MSZH, mszh); + REGISTER_DECODER(NUV, nuv); + REGISTER_ENCODER(PAM, pam); + REGISTER_ENCODER(PBM, pbm); + REGISTER_ENCODER(PGM, pgm); + REGISTER_ENCODER(PGMYUV, pgmyuv); +#ifdef CONFIG_ZLIB + REGISTER_ENCDEC (PNG, png); +#endif + REGISTER_ENCODER(PPM, ppm); + REGISTER_DECODER(QDRAW, qdraw); + REGISTER_DECODER(QPEG, qpeg); + REGISTER_DECODER(QTRLE, qtrle); + REGISTER_ENCDEC (RAWVIDEO, rawvideo); + REGISTER_DECODER(ROQ, roq); + REGISTER_DECODER(RPZA, rpza); + REGISTER_ENCDEC (RV10, rv10); + REGISTER_ENCDEC (RV20, rv20); + REGISTER_DECODER(SMACKER, smacker); + REGISTER_DECODER(SMC, smc); + REGISTER_ENCDEC (SNOW, snow); + REGISTER_DECODER(SP5X, sp5x); + REGISTER_ENCDEC (SVQ1, svq1); + REGISTER_DECODER(SVQ3, svq3); + REGISTER_DECODER(TARGA, targa); + REGISTER_DECODER(THEORA, theora); + REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo); + REGISTER_DECODER(TIFF, tiff); + REGISTER_DECODER(TRUEMOTION1, truemotion1); + REGISTER_DECODER(TRUEMOTION2, truemotion2); + REGISTER_DECODER(TSCC, tscc); + REGISTER_DECODER(ULTI, ulti); + REGISTER_DECODER(VC1, vc1); + REGISTER_DECODER(VCR1, vcr1); + REGISTER_DECODER(VMDVIDEO, vmdvideo); + REGISTER_DECODER(VMNC, vmnc); + REGISTER_DECODER(VP3, vp3); + REGISTER_DECODER(VP5, vp5); + REGISTER_DECODER(VP6, vp6); + REGISTER_DECODER(VP6F, vp6f); + REGISTER_DECODER(VQA, vqa); + REGISTER_ENCDEC (WMV1, wmv1); + REGISTER_ENCDEC (WMV2, wmv2); + REGISTER_DECODER(WMV3, wmv3); + REGISTER_DECODER(WNV1, wnv1); +#ifdef CONFIG_X264 + REGISTER_ENCODER(X264, x264); +#endif + REGISTER_DECODER(XAN_WC3, xan_wc3); + REGISTER_DECODER(XL, xl); +#ifdef CONFIG_XVID + REGISTER_ENCODER(XVID, xvid); +#endif + REGISTER_ENCDEC (ZLIB, zlib); +#ifdef CONFIG_ZLIB + REGISTER_ENCDEC (ZMBV, zmbv); +#endif + + /* audio codecs */ +#ifdef CONFIG_LIBFAAD + REGISTER_DECODER(AAC, aac); + REGISTER_DECODER(MPEG4AAC, mpeg4aac); +#endif +#ifdef CONFIG_LIBA52 + REGISTER_DECODER(AC3, ac3); +#endif + REGISTER_ENCODER(AC3, ac3); + REGISTER_DECODER(ALAC, alac); +#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) + REGISTER_ENCDEC (AMR_NB, amr_nb); +#endif +#ifdef CONFIG_AMR_WB + REGISTER_ENCDEC (AMR_WB, amr_wb); +#endif + REGISTER_DECODER(COOK, cook); + REGISTER_DECODER(DSICINAUDIO, dsicinaudio); +#ifdef CONFIG_LIBDTS + REGISTER_DECODER(DTS, dts); +#endif +#ifdef CONFIG_LIBFAAC + REGISTER_ENCODER(FAAC, faac); +#endif + REGISTER_ENCDEC (FLAC, flac); + REGISTER_DECODER(IMC, imc); +#ifdef CONFIG_LIBGSM + REGISTER_ENCDEC (LIBGSM, libgsm); +#endif + REGISTER_DECODER(MACE3, mace3); + REGISTER_DECODER(MACE6, mace6); + REGISTER_ENCDEC (MP2, mp2); + REGISTER_DECODER(MP3, mp3); + REGISTER_DECODER(MP3ADU, mp3adu); +#ifdef CONFIG_LIBMP3LAME + REGISTER_ENCODER(MP3LAME, mp3lame); +#endif + REGISTER_DECODER(MP3ON4, mp3on4); + REGISTER_DECODER(MPC7, mpc7); +#ifdef CONFIG_LIBVORBIS + if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis); + if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis); +#endif + REGISTER_DECODER(QDM2, qdm2); + REGISTER_DECODER(RA_144, ra_144); + REGISTER_DECODER(RA_288, ra_288); + REGISTER_DECODER(SHORTEN, shorten); + REGISTER_DECODER(SMACKAUD, smackaud); + REGISTER_ENCDEC (SONIC, sonic); + REGISTER_ENCODER(SONIC_LS, sonic_ls); + REGISTER_DECODER(TRUESPEECH, truespeech); + REGISTER_DECODER(TTA, tta); + REGISTER_DECODER(VMDAUDIO, vmdaudio); + REGISTER_ENCDEC (VORBIS, vorbis); + REGISTER_DECODER(WAVPACK, wavpack); + REGISTER_DECODER(WMAV1, wmav1); + REGISTER_DECODER(WMAV2, wmav2); + REGISTER_DECODER(WS_SND1, ws_snd1); + + /* pcm codecs */ + REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); + REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); + REGISTER_ENCDEC (PCM_S8, pcm_s8); + REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); + REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); + REGISTER_ENCDEC (PCM_S24BE, pcm_s24be); + REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud); + REGISTER_ENCDEC (PCM_S24LE, pcm_s24le); + REGISTER_ENCDEC (PCM_S32BE, pcm_s32be); + REGISTER_ENCDEC (PCM_S32LE, pcm_s32le); + REGISTER_ENCDEC (PCM_U8, pcm_u8); + REGISTER_ENCDEC (PCM_U16BE, pcm_u16be); + REGISTER_ENCDEC (PCM_U16LE, pcm_u16le); + REGISTER_ENCDEC (PCM_U24BE, pcm_u24be); + REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); + REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); + REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); + + /* dpcm codecs */ + REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm); + REGISTER_DECODER(ROQ_DPCM, roq_dpcm); + REGISTER_DECODER(SOL_DPCM, sol_dpcm); + REGISTER_DECODER(XAN_DPCM, xan_dpcm); + + /* adpcm codecs */ + REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm); + REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx); + REGISTER_ENCDEC (ADPCM_CT, adpcm_ct); + REGISTER_ENCDEC (ADPCM_EA, adpcm_ea); + REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); + REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3); + REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4); + REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt); + REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); + REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); + REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws); + REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); + REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2); + REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3); + REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4); + REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf); + REGISTER_ENCDEC (ADPCM_XA, adpcm_xa); + REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha); + + /* subtitles */ + REGISTER_ENCDEC (DVBSUB, dvbsub); + REGISTER_ENCDEC (DVDSUB, dvdsub); + + /* parsers */ + REGISTER_PARSER (AAC, aac); + REGISTER_PARSER (AC3, ac3); + REGISTER_PARSER (CAVSVIDEO, cavsvideo); + REGISTER_PARSER (DVBSUB, dvbsub); + REGISTER_PARSER (DVDSUB, dvdsub); + REGISTER_PARSER (H261, h261); + REGISTER_PARSER (H263, h263); + REGISTER_PARSER (H264, h264); + REGISTER_PARSER (MJPEG, mjpeg); + REGISTER_PARSER (MPEG4VIDEO, mpeg4video); + REGISTER_PARSER (MPEGAUDIO, mpegaudio); + REGISTER_PARSER (MPEGVIDEO, mpegvideo); + REGISTER_PARSER (PNM, pnm); + + /* + av_register_bitstream_filter(&dump_extradata_bsf); + av_register_bitstream_filter(&remove_extradata_bsf); + av_register_bitstream_filter(&noise_bsf); + av_register_bitstream_filter(&mp3_header_compress_bsf); + av_register_bitstream_filter(&mp3_header_decompress_bsf); + av_register_bitstream_filter(&mjpega_dump_header_bsf); + */ +} + +#endif + +void init_once_routine(void) { + pthread_mutex_init(&ffmpeg_lock, NULL); + avcodec_init(); + avcodec_register_all(); +} + +/* + * exported plugin catalog entry + */ + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_VIDEO_DECODER | PLUGIN_MUST_PRELOAD, 18, "ffmpegvideo", XINE_VERSION_CODE, &dec_info_ffmpeg_video, init_video_plugin }, + { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv8", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv8, init_video_plugin }, + { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv9", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv9, init_video_plugin }, + { PLUGIN_AUDIO_DECODER, 15, "ffmpegaudio", XINE_VERSION_CODE, &dec_info_ffmpeg_audio, init_audio_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/libffmpeg/ffmpeg_decoder.h b/src/libffmpeg/ffmpeg_decoder.h new file mode 100644 index 000000000..879ee3175 --- /dev/null +++ b/src/libffmpeg/ffmpeg_decoder.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2001-2005 the xine project + * + * This file is part of xine, a free 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: xine_decoder.h,v 1.7 2006/08/02 07:15:27 tmmm Exp $ + * + */ + +#ifndef HAVE_XINE_DECODER_H +#define HAVE_XINE_DECODER_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_FFMPEG +# include +#else +# include "libavcodec/avcodec.h" +#endif + +typedef struct ff_codec_s { + uint32_t type; + enum CodecID id; + const char *name; +} ff_codec_t; + +void *init_audio_plugin (xine_t *xine, void *data); +void *init_video_plugin (xine_t *xine, void *data); + +extern decoder_info_t dec_info_ffmpeg_video; +extern decoder_info_t dec_info_ffmpeg_wmv8; +extern decoder_info_t dec_info_ffmpeg_wmv9; +extern decoder_info_t dec_info_ffmpeg_audio; + +extern pthread_once_t once_control; +void init_once_routine(void); + +extern pthread_mutex_t ffmpeg_lock; + +#endif diff --git a/src/libffmpeg/ffmpeg_encoder.c b/src/libffmpeg/ffmpeg_encoder.c new file mode 100644 index 000000000..e234b4ddc --- /dev/null +++ b/src/libffmpeg/ffmpeg_encoder.c @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2000-2004 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: xine_encoder.c,v 1.25 2006/07/10 22:08:29 dgp85 Exp $ + */ + +/* mpeg encoders for the dxr3 video out plugin. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "dxr3_mpeg_encoder" +/* #define LOG_VERBOSE */ +/* #define LOG */ + +#include "video_out_dxr3.h" + +#ifdef HAVE_FFMPEG +# include +#else +# include "libavcodec/avcodec.h" +#endif + +/* buffer size for encoded mpeg1 stream; will hold one intra frame + * at 640x480 typical sizes are <50 kB. 512 kB should be plenty */ +#define DEFAULT_BUFFER_SIZE 512*1024 + + +/*initialisation function, used by the dxr3 plugin */ +int dxr3_encoder_init(dxr3_driver_t *drv) EXPORTED; + +/* functions required by encoder api */ +static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame); +static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame); +static int lavc_on_unneeded(dxr3_driver_t *drv); + +/*encoder structure*/ +typedef struct lavc_data_s { + encoder_data_t encoder_data; + AVCodecContext *context; /* handle for encoding */ + int width, height; /* width and height of the video frame */ + uint8_t *ffmpeg_buffer; /* lavc buffer */ + AVFrame *picture; /* picture to be encoded */ + uint8_t *out[3]; /* aligned buffer for YV12 data */ + uint8_t *buf; /* unaligned YV12 buffer */ +} lavc_data_t; + + +int dxr3_encoder_init(dxr3_driver_t *drv) +{ + lavc_data_t* this; + avcodec_init(); + + register_avcodec(&mpeg1video_encoder); + lprintf("lavc init , version %x\n", avcodec_version()); + this = xine_xmalloc(sizeof(lavc_data_t)); + if (!this) return 0; + + this->encoder_data.type = ENC_LAVC; + this->encoder_data.on_update_format = lavc_on_update_format; + this->encoder_data.on_frame_copy = NULL; + this->encoder_data.on_display_frame = lavc_on_display_frame; + this->encoder_data.on_unneeded = lavc_on_unneeded; + this->context = 0; + + drv->enc = &this->encoder_data; + return 1; +} + +/* helper function */ +static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame); + +static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame) +{ + lavc_data_t *this = (lavc_data_t *)drv->enc; + AVCodec *codec; + unsigned char use_quantizer; + + if (this->context) { + avcodec_close(this->context); + free(this->context); + free(this->picture); + this->context = NULL; + this->picture = NULL; + } + + /* if YUY2 and dimensions changed, we need to re-allocate the + * internal YV12 buffer */ + if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { + int image_size = frame->vo_frame.pitches[0] * frame->oheight; + + this->out[0] = xine_xmalloc_aligned(16, image_size * 3/2, + (void *)&this->buf); + this->out[1] = this->out[0] + image_size; + this->out[2] = this->out[1] + image_size/4; + + /* fill with black (yuv 16,128,128) */ + memset(this->out[0], 16, image_size); + memset(this->out[1], 128, image_size/4); + memset(this->out[2], 128, image_size/4); + lprintf("Using YUY2->YV12 conversion\n"); + } + + /* resolution must be a multiple of two */ + if ((frame->vo_frame.pitches[0] % 2 != 0) || (frame->oheight % 2 != 0)) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: lavc only handles video dimensions which are multiples of 2\n"); + return 0; + } + + /* get mpeg codec handle */ + codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); + if (!codec) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: lavc MPEG1 codec not found\n"); + return 0; + } + lprintf("lavc MPEG1 encoder found.\n"); + + this->width = frame->vo_frame.pitches[0]; + this->height = frame->oheight; + + this->context = avcodec_alloc_context(); + if (!this->context) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Couldn't start the ffmpeg library\n"); + return 0; + } + this->picture = avcodec_alloc_frame(); + if (!this->picture) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Couldn't allocate ffmpeg frame\n"); + return 0; + } + + /* mpeg1 encoder only support YUV420P */ + this->context->pix_fmt = PIX_FMT_YUVJ420P; + + /* put sample parameters */ + this->context->bit_rate = drv->class->xine->config->register_range(drv->class->xine->config, + "dxr3.encoding.lavc_bitrate", 10000, 1000, 20000, + _("libavcodec mpeg output bitrate (kbit/s)"), + _("The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. " + "Higher values will increase quality and CPU usage.\n" + "This setting is only considered, when constant quality mode is disabled."), 10, NULL, NULL); + this->context->bit_rate *= 1000; /* config in kbit/s, libavcodec wants bit/s */ + + use_quantizer = drv->class->xine->config->register_bool(drv->class->xine->config, + "dxr3.encoding.lavc_quantizer", 1, + _("constant quality mode"), + _("When enabled, libavcodec will use a constant quality mode by dynamically " + "compressing the images based on their complexity. When disabled, libavcodec " + "will use constant bitrate mode."), 10, NULL, NULL); + + if (use_quantizer) { + this->context->qmin = drv->class->xine->config->register_range(drv->class->xine->config, + "dxr3.encoding.lavc_qmin", 1, 1, 10, + _("minimum compression"), + _("The minimum compression to apply to an image in constant quality mode."), + 10, NULL, NULL); + + this->context->qmax = drv->class->xine->config->register_range(drv->class->xine->config, + "dxr3.encoding.lavc_qmax", 2, 1, 20, + _("maximum quantizer"), + _("The maximum compression to apply to an image in constant quality mode."), + 10, NULL, NULL); + } + + lprintf("lavc -> bitrate %d \n", this->context->bit_rate); + + this->context->width = frame->vo_frame.pitches[0]; + this->context->height = frame->oheight; + + this->context->gop_size = 0; /*intra frames only */ + this->context->me_method = ME_ZERO; /*motion estimation type*/ + + this->context->time_base.den = 90000; + if (frame->vo_frame.duration > 90000 / 24) + this->context->time_base.num = 90000 / 24; + else if (frame->vo_frame.duration < 90000 / 60) + this->context->time_base.num = 90000 / 60; + else + this->context->time_base.num = frame->vo_frame.duration; + /* ffmpeg can complain about illegal framerates, but since this seems no + * problem for the DXR3, we just tell ffmpeg to be more lax with */ + this->context->strict_std_compliance = -1; + + /* open avcodec */ + if (avcodec_open(this->context, codec) < 0) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, "dxr3_mpeg_encoder: could not open codec\n"); + return 0; + } + lprintf("dxr3_mpeg_encoder: lavc MPEG1 codec opened.\n"); + + if (!this->ffmpeg_buffer) + this->ffmpeg_buffer = (unsigned char *)malloc(DEFAULT_BUFFER_SIZE); /* why allocate more than needed ?! */ + if (!this->ffmpeg_buffer) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Couldn't allocate temp buffer for mpeg data\n"); + return 0; + } + + return 1; +} + +static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame) +{ + int size; + lavc_data_t* this = (lavc_data_t *)drv->enc; + ssize_t written; + + if (frame->vo_frame.bad_frame) return 1; + /* ignore old frames */ + if ((frame->vo_frame.pitches[0] != this->context->width) || (frame->oheight != this->context->height)) { + frame->vo_frame.free(&frame->vo_frame); + lprintf("LAVC ignoring frame !!!\n"); + return 1; + } + + /* prepare frame for conversion, handles YUY2 -> YV12 conversion when necessary */ + lavc_prepare_frame(this, drv, frame); + + /* do the encoding */ + size = avcodec_encode_video(this->context, this->ffmpeg_buffer, DEFAULT_BUFFER_SIZE, this->picture); + + frame->vo_frame.free(&frame->vo_frame); + + if (size < 0) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: encoding failed\n"); + return 0; + } + + written = write(drv->fd_video, this->ffmpeg_buffer, size); + if (written < 0) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: video device write failed (%s)\n", strerror(errno)); + return 0; + } + if (written != size) + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Could only write %zd of %d mpeg bytes.\n", written, size); + return 1; +} + +static int lavc_on_unneeded(dxr3_driver_t *drv) +{ + lavc_data_t *this = (lavc_data_t *)drv->enc; + lprintf("flushing buffers\n"); + if (this->context) { + avcodec_close(this->context); + free(this->context); + free(this->picture); + this->context = NULL; + this->picture = NULL; + } + return 1; +} + +static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame) +{ + int i, j, w2; + uint8_t *yuy2; + + if (frame->vo_frame.bad_frame) return 1; + + if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { + /* need YUY2->YV12 conversion */ + if (!(this->out[0] && this->out[1] && this->out[2]) ) { + lprintf("Internal YV12 buffer not created.\n"); + return 0; + } + this->picture->data[0] = this->out[0] + frame->vo_frame.pitches[0] * drv->top_bar; /* y */ + this->picture->data[1] = this->out[1] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* u */ + this->picture->data[2] = this->out[2] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* v */ + yuy2 = frame->vo_frame.base[0]; + w2 = frame->vo_frame.pitches[0] / 2; + for (i = 0; i < frame->vo_frame.height; i += 2) { + for (j = 0; j < w2; j++) { + /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */ + *(this->picture->data[0]++) = *(yuy2++); + *(this->picture->data[1]++) = *(yuy2++); + *(this->picture->data[0]++) = *(yuy2++); + *(this->picture->data[2]++) = *(yuy2++); + } + /* down sampling */ + for (j = 0; j < w2; j++) { + /* skip every second line for U and V */ + *(this->picture->data[0]++) = *(yuy2++); + yuy2++; + *(this->picture->data[0]++) = *(yuy2++); + yuy2++; + } + } + /* reset for encoder */ + this->picture->data[0] = this->out[0]; + this->picture->data[1] = this->out[1]; + this->picture->data[2] = this->out[2]; + } + else { /* YV12 **/ + this->picture->data[0] = frame->real_base[0]; + this->picture->data[1] = frame->real_base[1]; + this->picture->data[2] = frame->real_base[2]; + } + this->picture->linesize[0] = this->context->width; + this->picture->linesize[1] = this->context->width / 2; + this->picture->linesize[2] = this->context->width / 2; + return 1; +} diff --git a/src/libffmpeg/mpeg_parser.c b/src/libffmpeg/mpeg_parser.c deleted file mode 100644 index 14a08a456..000000000 --- a/src/libffmpeg/mpeg_parser.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright (C) 2001-2004 the xine project - * - * This file is part of xine, a free 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 - * - * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) - * based on libmpeg2 decoder. - * - * $Id: mpeg_parser.c,v 1.7 2007/03/29 18:52:45 dgp85 Exp $ - */ -#define LOG_MODULE "mpeg_parser" -#define LOG_VERBOSE -/* -#define LOG -*/ -#include "mpeg_parser.h" - -/* mpeg frame rate table from lavc */ -static const int frame_rate_tab[][2] = { - { 0, 0}, - {24000, 1001}, - { 24, 1}, - { 25, 1}, - {30000, 1001}, - { 30, 1}, - { 50, 1}, - {60000, 1001}, - { 60, 1}, - /* Xing's 15fps: (9) */ - { 15, 1}, - /* libmpeg3's "Unofficial economy rates": (10-13) */ - { 5, 1}, - { 10, 1}, - { 12, 1}, - { 15, 1}, - { 0, 0}, -}; - -void mpeg_parser_init (mpeg_parser_t *parser) -{ - parser->chunk_buffer = xine_xmalloc(BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); - mpeg_parser_reset(parser); -} - -void mpeg_parser_dispose (mpeg_parser_t *parser) -{ - if ( parser == NULL ) return; - - free(parser->chunk_buffer); -} - -void mpeg_parser_reset (mpeg_parser_t *parser) -{ - parser->shift = 0xffffff00; - parser->is_sequence_needed = 1; - parser->in_slice = 0; - parser->chunk_ptr = parser->chunk_buffer; - parser->chunk_start = parser->chunk_buffer; - parser->buffer_size = 0; - parser->code = 0xb4; - parser->picture_coding_type = 0; - parser->width = 0; - parser->height = 0; - parser->rate_code = 0; - parser->aspect_ratio_info = 0; - parser->frame_duration = 0; - parser->is_mpeg1 = 0; - parser->has_sequence = 0; - parser->frame_aspect_ratio = 0.0; -} - -static void parse_header_picture (mpeg_parser_t *parser, uint8_t * buffer) -{ - parser->picture_coding_type = (buffer [1] >> 3) & 7; -} - -static double get_aspect_ratio(mpeg_parser_t *parser) -{ - double ratio; - double mpeg1_pel_ratio[16] = {1.0 /* forbidden */, - 1.0, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, - 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 1.0 /*reserved*/ }; - - if( !parser->is_mpeg1 ) { - /* these hardcoded values are defined on mpeg2 standard for - * aspect ratio. other values are reserved or forbidden. */ - switch (parser->aspect_ratio_info) { - case 2: - ratio = 4.0 / 3.0; - break; - case 3: - ratio = 16.0 / 9.0; - break; - case 4: - ratio = 2.11 / 1.0; - break; - case 1: - default: - ratio = (double)parser->width / (double)parser->height; - break; - } - } else { - /* mpeg1 constants refer to pixel aspect ratio */ - ratio = (double)parser->width / (double)parser->height; - ratio /= mpeg1_pel_ratio[parser->aspect_ratio_info]; - } - - return ratio; -} - -static int parse_chunk (mpeg_parser_t *parser, int code, uint8_t *buffer, int len) -{ - int is_frame_done; - int next_code = parser->code; - - /* wait for sequence_header_code */ - if (parser->is_sequence_needed) { - if (code != 0xb3) { - lprintf("waiting for sequence header\n"); - parser->chunk_ptr = parser->chunk_buffer; - return 0; - } - } - - is_frame_done = parser->in_slice && ((!next_code) || (next_code == 0xb7)); - - if (is_frame_done) - parser->in_slice = 0; - - switch (code) { - case 0x00: /* picture_start_code */ - - parse_header_picture (parser, buffer); - - parser->in_slice = 1; - - switch (parser->picture_coding_type) { - case B_TYPE: - lprintf ("B-Frame\n"); - break; - - case P_TYPE: - lprintf ("P-Frame\n"); - break; - - case I_TYPE: - lprintf ("I-Frame\n"); - break; - } - break; - - case 0xb2: /* user data code */ - /* process_userdata(mpeg2dec, buffer); */ - break; - - case 0xb3: /* sequence_header_code */ - { - int value; - uint16_t width, height; - - if (parser->is_sequence_needed) { - parser->is_sequence_needed = 0; - } - - if ((buffer[6] & 0x20) != 0x20) { - lprintf("Invalid sequence: missing marker_bit\n"); - parser->has_sequence = 0; - break; /* missing marker_bit */ - } - - value = (buffer[0] << 16) | - (buffer[1] << 8) | - buffer[2]; - width = ((value >> 12) + 15) & ~15; - height = ((value & 0xfff) + 15) & ~15; - - if ((width > 1920) || (height > 1152)) { - lprintf("Invalid sequence: width=%d, height=%d\n", width, height); - parser->has_sequence = 0; - break; /* size restrictions for MP@HL */ - } - - parser->width = width; - parser->height = height; - parser->rate_code = buffer[3] & 15; - parser->aspect_ratio_info = buffer[3] >> 4; - - if (parser->rate_code < (sizeof(frame_rate_tab)/sizeof(*frame_rate_tab))) { - parser->frame_duration = 90000; - parser->frame_duration *= frame_rate_tab[parser->rate_code][1]; - parser->frame_duration /= frame_rate_tab[parser->rate_code][0]; - } else { - printf ("invalid/unknown frame rate code : %d \n", - parser->rate_code); - parser->frame_duration = 0; - } - - parser->has_sequence = 1; - parser->is_mpeg1 = 1; - } - break; - - case 0xb5: /* extension_start_code */ - switch (buffer[0] & 0xf0) { - case 0x10: /* sequence extension */ - parser->is_mpeg1 = 0; - } - - default: - if (code >= 0xb9) - lprintf ("stream not demultiplexed ?\n"); - - if (code >= 0xb0) - break; - } - return is_frame_done; -} - -static inline uint8_t *copy_chunk (mpeg_parser_t *parser, - uint8_t *current, uint8_t *end) -{ - uint32_t shift; - uint8_t *chunk_ptr; - uint8_t *limit; - uint8_t byte; - - shift = parser->shift; - chunk_ptr = parser->chunk_ptr; - - limit = current + (parser->chunk_buffer + BUFFER_SIZE - chunk_ptr); - if (limit > end) - limit = end; - - while (1) { - - byte = *current++; - *chunk_ptr++ = byte; - if (shift != 0x00000100) { - shift = (shift | byte) << 8; - if (current < limit) - continue; - if (current == end) { - parser->chunk_ptr = chunk_ptr; - parser->shift = shift; - lprintf("Need more bytes\n"); - return NULL; - } else { - /* we filled the chunk buffer without finding a start code */ - lprintf("Buffer full\n"); - parser->code = 0xb4; /* sequence_error_code */ - parser->chunk_ptr = parser->chunk_buffer; - return current; - } - } - lprintf("New chunk: 0x%2X\n", byte); - parser->chunk_ptr = chunk_ptr; - parser->shift = 0xffffff00; - parser->code = byte; - return current; - } -} - - -uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, - uint8_t *current, uint8_t *end, - int *flush) -{ - int ret; - uint8_t code; - - ret = 0; - *flush = 0; - - while (current != end) { - if (parser->chunk_ptr == parser->chunk_buffer) { - /* write the beginning of the chunk */ - parser->chunk_buffer[0] = 0x00; - parser->chunk_buffer[1] = 0x00; - parser->chunk_buffer[2] = 0x01; - parser->chunk_buffer[3] = parser->code; - parser->chunk_ptr += 4; - parser->chunk_start = parser->chunk_ptr; - parser->has_sequence = 0; - } - - code = parser->code; - - current = copy_chunk (parser, current, end); - if (current == NULL) - return NULL; - ret = parse_chunk (parser, code, parser->chunk_start, - parser->chunk_ptr - parser->chunk_start - 4); - parser->chunk_start = parser->chunk_ptr; - if (ret == 1) { - if (parser->has_sequence) { - parser->frame_aspect_ratio = get_aspect_ratio(parser); - } - parser->buffer_size = parser->chunk_ptr - parser->chunk_buffer - 4; - parser->chunk_ptr = parser->chunk_buffer; - - if (parser->code == 0xb7) /* sequence end, maybe a still menu */ - *flush = 1; - - return current; - } - } - - return NULL; -} diff --git a/src/libffmpeg/mpeg_parser.h b/src/libffmpeg/mpeg_parser.h deleted file mode 100644 index 859a0fcec..000000000 --- a/src/libffmpeg/mpeg_parser.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2001-2004 the xine project - * - * This file is part of xine, a free 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 - * - * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) - * based on libmpeg2 decoder. - * - * $Id: mpeg_parser.h,v 1.5 2007/03/29 18:52:45 dgp85 Exp $ - */ -#ifndef HAVE_MPEG_PARSER_H -#define HAVE_MPEG_PARSER_H - -#include "xine_internal.h" -#include "xine_decoder.h" - -#define BUFFER_SIZE (1194 * 1024) /* libmpeg2's buffer size */ - -/* picture coding type (mpeg2 header) */ -#define I_TYPE 1 -#define P_TYPE 2 -#define B_TYPE 3 -#define D_TYPE 4 - -typedef struct mpeg_parser_s { - uint8_t *chunk_buffer; - uint8_t *chunk_ptr; - uint8_t *chunk_start; - uint32_t shift; - int buffer_size; - uint8_t code; - uint8_t picture_coding_type; - - uint8_t is_sequence_needed:1; - uint8_t is_mpeg1:1; /* public */ - uint8_t has_sequence:1; /* public */ - uint8_t in_slice:1; - - uint8_t rate_code:4; - - int aspect_ratio_info; - - /* public properties */ - uint16_t width; - uint16_t height; - int frame_duration; - double frame_aspect_ratio; - -} mpeg_parser_t; - -/* parser initialization */ -void mpeg_parser_init (mpeg_parser_t *parser); - -/* parser disposal */ -void mpeg_parser_dispose (mpeg_parser_t *parser); - -/* read a frame - * return a pointer to the first byte of the next frame - * or NULL if more bytes are needed - * *flush is set to 1 if the decoder must be flushed (needed for still menus) - */ -uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, - uint8_t *current, uint8_t *end, - int *flush); - -/* reset the parser */ -void mpeg_parser_reset (mpeg_parser_t *parser); - -#endif /* HAVE_MPEG_PARSER_H */ diff --git a/src/libffmpeg/video_decoder.c b/src/libffmpeg/video_decoder.c deleted file mode 100644 index 38cf160c5..000000000 --- a/src/libffmpeg/video_decoder.c +++ /dev/null @@ -1,1772 +0,0 @@ -/* - * Copyright (C) 2001-2007 the xine project - * - * This file is part of xine, a free 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: video_decoder.c,v 1.73 2007/03/29 18:41:02 dgp85 Exp $ - * - * xine video decoder plugin using ffmpeg - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "ffmpeg_config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "ffmpeg_video_dec" -#define LOG_VERBOSE -/* -#define LOG -*/ -#include "xine_internal.h" -#include "bswap.h" -#include "buffer.h" -#include "xineutils.h" -#include "xine_decoder.h" -#include "mpeg_parser.h" - -#ifdef HAVE_FFMPEG -# include -#else -# include "libavcodec/libpostproc/postprocess.h" -#endif - -#define VIDEOBUFSIZE (128*1024) -#define SLICE_BUFFER_SIZE (1194*1024) - -#define SLICE_OFFSET_SIZE 128 - -#define ENABLE_DIRECT_RENDERING - -typedef struct ff_video_decoder_s ff_video_decoder_t; - -typedef struct ff_video_class_s { - video_decoder_class_t decoder_class; - - int pp_quality; - - xine_t *xine; -} ff_video_class_t; - -struct ff_video_decoder_s { - video_decoder_t video_decoder; - - ff_video_class_t *class; - - xine_stream_t *stream; - int64_t pts; - int video_step; - - uint8_t decoder_ok:1; - uint8_t decoder_init_mode:1; - uint8_t is_mpeg12:1; - uint8_t pp_available:1; - uint8_t yuv_init:1; - uint8_t is_direct_rendering_disabled:1; - uint8_t cs_convert_init:1; - - xine_bmiheader bih; - unsigned char *buf; - int bufsize; - int size; - int skipframes; - - int slice_offset_size; - - AVFrame *av_frame; - AVCodecContext *context; - AVCodec *codec; - - int pp_quality; - int pp_flags; - pp_context_t *pp_context; - pp_mode_t *pp_mode; - - /* mpeg-es parsing */ - mpeg_parser_t *mpeg_parser; - - double aspect_ratio; - int aspect_ratio_prio; - int frame_flags; - int crop_right, crop_bottom; - - int output_format; - - xine_list_t *dr1_frames; - - yuv_planes_t yuv; - - AVPaletteControl palette_control; -}; - - -static void set_stream_info(ff_video_decoder_t *this) { - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->bih.biWidth); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->bih.biHeight); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, this->aspect_ratio * 10000); -} - -#ifdef ENABLE_DIRECT_RENDERING -/* called from ffmpeg to do direct rendering method 1 */ -static int get_buffer(AVCodecContext *context, AVFrame *av_frame){ - ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; - vo_frame_t *img; - int width = context->width; - int height = context->height; - - if (!this->bih.biWidth || !this->bih.biHeight) { - this->bih.biWidth = width; - this->bih.biHeight = height; - - if (this->aspect_ratio_prio == 0) { - this->aspect_ratio = (double)width / (double)height; - this->aspect_ratio_prio = 1; - lprintf("default aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - } - - avcodec_align_dimensions(context, &width, &height); - - if( this->context->pix_fmt != PIX_FMT_YUV420P ) { - if (!this->is_direct_rendering_disabled) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n")); - this->is_direct_rendering_disabled = 1; - } - - /* FIXME: why should i have to do that ? */ - av_frame->data[0]= NULL; - av_frame->data[1]= NULL; - av_frame->data[2]= NULL; - return avcodec_default_get_buffer(context, av_frame); - } - - if((width != this->bih.biWidth) || (height != this->bih.biHeight)) { - if(this->stream->video_out->get_capabilities(this->stream->video_out) & VO_CAP_CROP) { - this->crop_right = width - this->bih.biWidth; - this->crop_bottom = height - this->bih.biHeight; - } else { - if (!this->is_direct_rendering_disabled) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n")); - this->is_direct_rendering_disabled = 1; - } - /* FIXME: why should i have to do that ? */ - av_frame->data[0]= NULL; - av_frame->data[1]= NULL; - av_frame->data[2]= NULL; - return avcodec_default_get_buffer(context, av_frame); - } - } - - img = this->stream->video_out->get_frame (this->stream->video_out, - width, - height, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - - av_frame->opaque = img; - - av_frame->data[0]= img->base[0]; - av_frame->data[1]= img->base[1]; - av_frame->data[2]= img->base[2]; - - av_frame->linesize[0] = img->pitches[0]; - av_frame->linesize[1] = img->pitches[1]; - av_frame->linesize[2] = img->pitches[2]; - - /* We should really keep track of the ages of xine frames (see - * avcodec_default_get_buffer in libavcodec/utils.c) - * For the moment tell ffmpeg that every frame is new (age = bignumber) */ - av_frame->age = 256*256*256*64; - - av_frame->type= FF_BUFFER_TYPE_USER; - - xine_list_push_back(this->dr1_frames, av_frame); - - return 0; -} - -static void release_buffer(struct AVCodecContext *context, AVFrame *av_frame){ - ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; - - if (av_frame->type == FF_BUFFER_TYPE_USER) { - vo_frame_t *img = (vo_frame_t *)av_frame->opaque; - xine_list_iterator_t it; - - assert(av_frame->opaque); - img->free(img); - - it = xine_list_find(this->dr1_frames, av_frame); - assert(it); - if( it != NULL ) - xine_list_remove(this->dr1_frames, it); - } else { - avcodec_default_release_buffer(context, av_frame); - } - - av_frame->opaque = NULL; - av_frame->data[0]= NULL; - av_frame->data[1]= NULL; - av_frame->data[2]= NULL; -} -#endif - -static const ff_codec_t ff_video_lookup[] = { - {BUF_VIDEO_MSMPEG4_V1, CODEC_ID_MSMPEG4V1, "Microsoft MPEG-4 v1 (ffmpeg)"}, - {BUF_VIDEO_MSMPEG4_V2, CODEC_ID_MSMPEG4V2, "Microsoft MPEG-4 v2 (ffmpeg)"}, - {BUF_VIDEO_MSMPEG4_V3, CODEC_ID_MSMPEG4V3, "Microsoft MPEG-4 v3 (ffmpeg)"}, - {BUF_VIDEO_WMV7, CODEC_ID_WMV1, "MS Windows Media Video 7 (ffmpeg)"}, - {BUF_VIDEO_WMV8, CODEC_ID_WMV2, "MS Windows Media Video 8 (ffmpeg)"}, - {BUF_VIDEO_WMV9, CODEC_ID_WMV3, "MS Windows Media Video 9 (ffmpeg)"}, - {BUF_VIDEO_MPEG4, CODEC_ID_MPEG4, "ISO MPEG-4 (ffmpeg)"}, - {BUF_VIDEO_XVID, CODEC_ID_MPEG4, "ISO MPEG-4 (XviD, ffmpeg)"}, - {BUF_VIDEO_DIVX5, CODEC_ID_MPEG4, "ISO MPEG-4 (DivX5, ffmpeg)"}, - {BUF_VIDEO_3IVX, CODEC_ID_MPEG4, "ISO MPEG-4 (3ivx, ffmpeg)"}, - {BUF_VIDEO_JPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, - {BUF_VIDEO_MJPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, - {BUF_VIDEO_MJPEG_B, CODEC_ID_MJPEGB, "Motion JPEG B (ffmpeg)"}, - {BUF_VIDEO_I263, CODEC_ID_H263I, "ITU H.263 (ffmpeg)"}, - {BUF_VIDEO_H263, CODEC_ID_H263, "H.263 (ffmpeg)"}, - {BUF_VIDEO_RV10, CODEC_ID_RV10, "Real Video 1.0 (ffmpeg)"}, - {BUF_VIDEO_RV20, CODEC_ID_RV20, "Real Video 2.0 (ffmpeg)"}, - {BUF_VIDEO_IV31, CODEC_ID_INDEO3, "Indeo Video 3.1 (ffmpeg)"}, - {BUF_VIDEO_IV32, CODEC_ID_INDEO3, "Indeo Video 3.2 (ffmpeg)"}, - {BUF_VIDEO_SORENSON_V1, CODEC_ID_SVQ1, "Sorenson Video 1 (ffmpeg)"}, - {BUF_VIDEO_SORENSON_V3, CODEC_ID_SVQ3, "Sorenson Video 3 (ffmpeg)"}, - {BUF_VIDEO_DV, CODEC_ID_DVVIDEO, "DV (ffmpeg)"}, - {BUF_VIDEO_HUFFYUV, CODEC_ID_HUFFYUV, "HuffYUV (ffmpeg)"}, - {BUF_VIDEO_VP31, CODEC_ID_VP3, "On2 VP3.1 (ffmpeg)"}, - {BUF_VIDEO_VP5, CODEC_ID_VP5, "On2 VP5 (ffmpeg)"}, - {BUF_VIDEO_VP6, CODEC_ID_VP6, "On2 VP6 (ffmpeg)"}, - {BUF_VIDEO_VP6F, CODEC_ID_VP6F, "On2 VP6 (ffmpeg)"}, - {BUF_VIDEO_4XM, CODEC_ID_4XM, "4X Video (ffmpeg)"}, - {BUF_VIDEO_CINEPAK, CODEC_ID_CINEPAK, "Cinepak (ffmpeg)"}, - {BUF_VIDEO_MSVC, CODEC_ID_MSVIDEO1, "Microsoft Video 1 (ffmpeg)"}, - {BUF_VIDEO_MSRLE, CODEC_ID_MSRLE, "Microsoft RLE (ffmpeg)"}, - {BUF_VIDEO_RPZA, CODEC_ID_RPZA, "Apple Quicktime Video/RPZA (ffmpeg)"}, - {BUF_VIDEO_CYUV, CODEC_ID_CYUV, "Creative YUV (ffmpeg)"}, - {BUF_VIDEO_ROQ, CODEC_ID_ROQ, "Id Software RoQ (ffmpeg)"}, - {BUF_VIDEO_IDCIN, CODEC_ID_IDCIN, "Id Software CIN (ffmpeg)"}, - {BUF_VIDEO_WC3, CODEC_ID_XAN_WC3, "Xan (ffmpeg)"}, - {BUF_VIDEO_VQA, CODEC_ID_WS_VQA, "Westwood Studios VQA (ffmpeg)"}, - {BUF_VIDEO_INTERPLAY, CODEC_ID_INTERPLAY_VIDEO, "Interplay MVE (ffmpeg)"}, - {BUF_VIDEO_FLI, CODEC_ID_FLIC, "FLIC Video (ffmpeg)"}, - {BUF_VIDEO_8BPS, CODEC_ID_8BPS, "Planar RGB (ffmpeg)"}, - {BUF_VIDEO_SMC, CODEC_ID_SMC, "Apple Quicktime Graphics/SMC (ffmpeg)"}, - {BUF_VIDEO_DUCKTM1, CODEC_ID_TRUEMOTION1,"Duck TrueMotion v1 (ffmpeg)"}, - {BUF_VIDEO_DUCKTM2, CODEC_ID_TRUEMOTION2,"Duck TrueMotion v2 (ffmpeg)"}, - {BUF_VIDEO_VMD, CODEC_ID_VMDVIDEO, "Sierra VMD Video (ffmpeg)"}, - {BUF_VIDEO_ZLIB, CODEC_ID_ZLIB, "ZLIB Video (ffmpeg)"}, - {BUF_VIDEO_MSZH, CODEC_ID_MSZH, "MSZH Video (ffmpeg)"}, - {BUF_VIDEO_ASV1, CODEC_ID_ASV1, "ASV v1 Video (ffmpeg)"}, - {BUF_VIDEO_ASV2, CODEC_ID_ASV2, "ASV v2 Video (ffmpeg)"}, - {BUF_VIDEO_ATIVCR1, CODEC_ID_VCR1, "ATI VCR-1 (ffmpeg)"}, - {BUF_VIDEO_FLV1, CODEC_ID_FLV1, "Flash Video (ffmpeg)"}, - {BUF_VIDEO_QTRLE, CODEC_ID_QTRLE, "Apple Quicktime Animation/RLE (ffmpeg)"}, - {BUF_VIDEO_H264, CODEC_ID_H264, "H.264/AVC (ffmpeg)"}, - {BUF_VIDEO_H261, CODEC_ID_H261, "H.261 (ffmpeg)"}, - {BUF_VIDEO_AASC, CODEC_ID_AASC, "Autodesk Video (ffmpeg)"}, - {BUF_VIDEO_LOCO, CODEC_ID_LOCO, "LOCO (ffmpeg)"}, - {BUF_VIDEO_QDRW, CODEC_ID_QDRAW, "QuickDraw (ffmpeg)"}, - {BUF_VIDEO_QPEG, CODEC_ID_QPEG, "Q-Team QPEG (ffmpeg)"}, - {BUF_VIDEO_TSCC, CODEC_ID_TSCC, "TechSmith Video (ffmpeg)"}, - {BUF_VIDEO_ULTI, CODEC_ID_ULTI, "IBM UltiMotion (ffmpeg)"}, - {BUF_VIDEO_WNV1, CODEC_ID_WNV1, "Winnow Video (ffmpeg)"}, - {BUF_VIDEO_XL, CODEC_ID_VIXL, "Miro/Pinnacle VideoXL (ffmpeg)"}, - {BUF_VIDEO_RT21, CODEC_ID_INDEO2, "Indeo/RealTime 2 (ffmpeg)"}, - {BUF_VIDEO_FPS1, CODEC_ID_FRAPS, "Fraps (ffmpeg)"}, - {BUF_VIDEO_MPEG, CODEC_ID_MPEG1VIDEO, "MPEG 1/2 (ffmpeg)"}, - {BUF_VIDEO_CSCD, CODEC_ID_CSCD, "CamStudio (ffmpeg)"}, - {BUF_VIDEO_AVS, CODEC_ID_AVS, "AVS (ffmpeg)"}, - {BUF_VIDEO_ALGMM, CODEC_ID_MMVIDEO, "American Laser Games MM (ffmpeg)"}, - {BUF_VIDEO_ZMBV, CODEC_ID_ZMBV, "Zip Motion Blocks Video (ffmpeg)"}, - {BUF_VIDEO_SMACKER, CODEC_ID_SMACKVIDEO, "Smacker (ffmpeg)"}, - {BUF_VIDEO_NUV, CODEC_ID_NUV, "NuppelVideo (ffmpeg)"}, - {BUF_VIDEO_KMVC, CODEC_ID_KMVC, "Karl Morton's Video Codec (ffmpeg)"}, - {BUF_VIDEO_FLASHSV, CODEC_ID_FLASHSV, "Flash Screen Video (ffmpeg)"}, - {BUF_VIDEO_CAVS, CODEC_ID_CAVS, "Chinese AVS (ffmpeg)"}, -}; - - -static void init_video_codec (ff_video_decoder_t *this, unsigned int codec_type) { - size_t i; - - /* find the decoder */ - this->codec = NULL; - - for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++) - if(ff_video_lookup[i].type == codec_type) { - pthread_mutex_lock(&ffmpeg_lock); - this->codec = avcodec_find_decoder(ff_video_lookup[i].id); - pthread_mutex_unlock(&ffmpeg_lock); - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, - ff_video_lookup[i].name); - break; - } - - if (!this->codec) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), - codec_type); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); - return; - } - - lprintf("lavc decoder found\n"); - - /* force (width % 8 == 0), otherwise there will be - * display problems with Xv. - */ - this->bih.biWidth = (this->bih.biWidth + 1) & (~1); - - this->context->width = this->bih.biWidth; - this->context->height = this->bih.biHeight; - this->context->stream_codec_tag = this->context->codec_tag = - _x_stream_info_get(this->stream, XINE_STREAM_INFO_VIDEO_FOURCC); - - - /* Some codecs (eg rv10) copy flags in init so it's necessary to set - * this flag here in case we are going to use direct rendering */ - if(this->codec->capabilities & CODEC_CAP_DR1) { - this->context->flags |= CODEC_FLAG_EMU_EDGE; - } - - pthread_mutex_lock(&ffmpeg_lock); - if (avcodec_open (this->context, this->codec) < 0) { - pthread_mutex_unlock(&ffmpeg_lock); - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: couldn't open decoder\n")); - free(this->context); - this->context = NULL; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); - return; - } - pthread_mutex_unlock(&ffmpeg_lock); - - lprintf("lavc decoder opened\n"); - - this->decoder_ok = 1; - - if ((codec_type != BUF_VIDEO_MPEG) && - (codec_type != BUF_VIDEO_DV)) { - - if (!this->bih.biWidth || !this->bih.biHeight) { - this->bih.biWidth = this->context->width; - this->bih.biHeight = this->context->height; - } - - - set_stream_info(this); - } - - this->stream->video_out->open (this->stream->video_out, this->stream); - - this->skipframes = 0; - - /* enable direct rendering by default */ - this->output_format = XINE_IMGFMT_YV12; -#ifdef ENABLE_DIRECT_RENDERING - if( this->codec->capabilities & CODEC_CAP_DR1 && this->codec->id != CODEC_ID_H264 ) { - this->context->get_buffer = get_buffer; - this->context->release_buffer = release_buffer; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: direct rendering enabled\n")); - } -#endif - - /* flag for interlaced streams */ - this->frame_flags = 0; - /* FIXME: which codecs can be interlaced? - FIXME: check interlaced DCT and other codec specific info. */ - switch( codec_type ) { - case BUF_VIDEO_DV: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_MPEG: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_MJPEG: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_HUFFYUV: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - } - -} - -static void pp_quality_cb(void *user_data, xine_cfg_entry_t *entry) { - ff_video_class_t *class = (ff_video_class_t *) user_data; - - class->pp_quality = entry->num_value; -} - -static void pp_change_quality (ff_video_decoder_t *this) { - this->pp_quality = this->class->pp_quality; - - if(this->pp_available && this->pp_quality) { - if(!this->pp_context && this->context) - this->pp_context = pp_get_context(this->context->width, this->context->height, - this->pp_flags); - if(this->pp_mode) - pp_free_mode(this->pp_mode); - - this->pp_mode = pp_get_mode_by_name_and_quality("hb:a,vb:a,dr:a", - this->pp_quality); - } else { - if(this->pp_mode) { - pp_free_mode(this->pp_mode); - this->pp_mode = NULL; - } - - if(this->pp_context) { - pp_free_context(this->pp_context); - this->pp_context = NULL; - } - } -} - -static void init_postprocess (ff_video_decoder_t *this) { - uint32_t cpu_caps; - - /* Allow post processing on mpeg-4 (based) codecs */ - switch(this->codec->id) { - case CODEC_ID_MPEG4: - case CODEC_ID_MSMPEG4V1: - case CODEC_ID_MSMPEG4V2: - case CODEC_ID_MSMPEG4V3: - case CODEC_ID_WMV1: - case CODEC_ID_WMV2: - this->pp_available = 1; - break; - default: - this->pp_available = 0; - break; - } - - /* Detect what cpu accel we have */ - cpu_caps = xine_mm_accel(); - this->pp_flags = PP_FORMAT_420; - - if(cpu_caps & MM_ACCEL_X86_MMX) - this->pp_flags |= PP_CPU_CAPS_MMX; - - if(cpu_caps & MM_ACCEL_X86_MMXEXT) - this->pp_flags |= PP_CPU_CAPS_MMX2; - - if(cpu_caps & MM_ACCEL_X86_3DNOW) - this->pp_flags |= PP_CPU_CAPS_3DNOW; - - /* Set level */ - pp_change_quality(this); -} - -static int ff_handle_mpeg_sequence(ff_video_decoder_t *this, mpeg_parser_t *parser) { - - /* - * init codec - */ - if (this->decoder_init_mode) { - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, - "mpeg-1 (ffmpeg)"); - - init_video_codec (this, BUF_VIDEO_MPEG); - this->decoder_init_mode = 0; - } - - /* frame format change */ - if ((parser->width != this->bih.biWidth) || - (parser->height != this->bih.biHeight) || - (parser->frame_aspect_ratio != this->aspect_ratio)) { - xine_event_t event; - xine_format_change_data_t data; - - this->bih.biWidth = parser->width; - this->bih.biHeight = parser->height; - this->aspect_ratio = parser->frame_aspect_ratio; - this->aspect_ratio_prio = 2; - lprintf("mpeg seq aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - - event.type = XINE_EVENT_FRAME_FORMAT_CHANGE; - event.stream = this->stream; - event.data = &data; - event.data_length = sizeof(data); - data.width = this->bih.biWidth; - data.height = this->bih.biHeight; - data.aspect = this->aspect_ratio; - data.pan_scan = 0; - xine_event_send(this->stream, &event); - } - this->video_step = this->mpeg_parser->frame_duration; - - return 1; -} - -static void ff_convert_frame(ff_video_decoder_t *this, vo_frame_t *img) { - int y; - uint8_t *dy, *du, *dv, *sy, *su, *sv; - - dy = img->base[0]; - du = img->base[1]; - dv = img->base[2]; - sy = this->av_frame->data[0]; - su = this->av_frame->data[1]; - sv = this->av_frame->data[2]; - - if (this->context->pix_fmt == PIX_FMT_YUV410P) { - - yuv9_to_yv12( - /* Y */ - this->av_frame->data[0], - this->av_frame->linesize[0], - img->base[0], - img->pitches[0], - /* U */ - this->av_frame->data[1], - this->av_frame->linesize[1], - img->base[1], - img->pitches[1], - /* V */ - this->av_frame->data[2], - this->av_frame->linesize[2], - img->base[2], - img->pitches[2], - /* width x height */ - img->width, - img->height); - - } else if (this->context->pix_fmt == PIX_FMT_YUV411P) { - - yuv411_to_yv12( - /* Y */ - this->av_frame->data[0], - this->av_frame->linesize[0], - img->base[0], - img->pitches[0], - /* U */ - this->av_frame->data[1], - this->av_frame->linesize[1], - img->base[1], - img->pitches[1], - /* V */ - this->av_frame->data[2], - this->av_frame->linesize[2], - img->base[2], - img->pitches[2], - /* width x height */ - img->width, - img->height); - - } else if (this->context->pix_fmt == PIX_FMT_RGBA32) { - - int x, plane_ptr = 0; - uint32_t *argb_pixels; - uint32_t argb; - - for(y = 0; y < img->height; y++) { - argb_pixels = (uint32_t *)sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - /* this is endian-safe as the ARGB pixels are stored in - * machine order */ - argb = *argb_pixels++; - r = (argb >> 16) & 0xFF; - g = (argb >> 8) & 0xFF; - b = (argb >> 0) & 0xFF; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_RGB565) { - - int x, plane_ptr = 0; - uint8_t *src; - uint16_t pixel16; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - /* a 16-bit RGB565 pixel is supposed to be stored in native-endian - * byte order; the following should be endian-safe */ - pixel16 = *((uint16_t *)src); - src += 2; - b = (pixel16 << 3) & 0xFF; - g = (pixel16 >> 3) & 0xFF; - r = (pixel16 >> 8) & 0xFF; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_RGB555) { - - int x, plane_ptr = 0; - uint8_t *src; - uint16_t pixel16; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - /* a 16-bit RGB555 pixel is supposed to be stored in native-endian - * byte order; the following should be endian-safe */ - pixel16 = *((uint16_t *)src); - src += 2; - b = (pixel16 << 3) & 0xFF; - g = (pixel16 >> 2) & 0xFF; - r = (pixel16 >> 7) & 0xFF; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_BGR24) { - - int x, plane_ptr = 0; - uint8_t *src; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - b = *src++; - g = *src++; - r = *src++; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_RGB24) { - - int x, plane_ptr = 0; - uint8_t *src; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - r = *src++; - g = *src++; - b = *src++; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_PAL8) { - - int x, plane_ptr = 0; - uint8_t *src; - uint8_t pixel; - uint32_t *palette32 = (uint32_t *)su; /* palette is in data[1] */ - uint32_t rgb_color; - uint8_t r, g, b; - uint8_t y_palette[256]; - uint8_t u_palette[256]; - uint8_t v_palette[256]; - - for (x = 0; x < 256; x++) { - rgb_color = palette32[x]; - b = rgb_color & 0xFF; - rgb_color >>= 8; - g = rgb_color & 0xFF; - rgb_color >>= 8; - r = rgb_color & 0xFF; - y_palette[x] = COMPUTE_Y(r, g, b); - u_palette[x] = COMPUTE_U(r, g, b); - v_palette[x] = COMPUTE_V(r, g, b); - } - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - pixel = *src++; - - this->yuv.y[plane_ptr] = y_palette[pixel]; - this->yuv.u[plane_ptr] = u_palette[pixel]; - this->yuv.v[plane_ptr] = v_palette[pixel]; - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else { - - for (y=0; yheight; y++) { - xine_fast_memcpy (dy, sy, img->width); - - dy += img->pitches[0]; - - sy += this->av_frame->linesize[0]; - } - - for (y=0; y<(img->height/2); y++) { - - if (this->context->pix_fmt != PIX_FMT_YUV444P) { - - xine_fast_memcpy (du, su, img->width/2); - xine_fast_memcpy (dv, sv, img->width/2); - - } else { - - int x; - uint8_t *src; - uint8_t *dst; - - /* subsample */ - - src = su; dst = du; - for (x=0; x<(img->width/2); x++) { - *dst = *src; - dst++; - src += 2; - } - src = sv; dst = dv; - for (x=0; x<(img->width/2); x++) { - *dst = *src; - dst++; - src += 2; - } - - } - - du += img->pitches[1]; - dv += img->pitches[2]; - - if (this->context->pix_fmt != PIX_FMT_YUV420P) { - su += 2*this->av_frame->linesize[1]; - sv += 2*this->av_frame->linesize[2]; - } else { - su += this->av_frame->linesize[1]; - sv += this->av_frame->linesize[2]; - } - } - } -} - -static void ff_check_bufsize (ff_video_decoder_t *this, int size) { - if (size > this->bufsize) { - this->bufsize = size + size / 2; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc(this->buf, this->bufsize + FF_INPUT_BUFFER_PADDING_SIZE ); - } -} - -static void ff_handle_preview_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - int codec_type; - - lprintf ("preview buffer\n"); - - codec_type = buf->type & 0xFFFF0000; - if (codec_type == BUF_VIDEO_MPEG) { - this->is_mpeg12 = 1; - if ( this->mpeg_parser == NULL ) { - this->mpeg_parser = xine_xmalloc(sizeof(mpeg_parser_t)); - mpeg_parser_init(this->mpeg_parser); - this->decoder_init_mode = 0; - } - } - - if (this->decoder_init_mode && !this->is_mpeg12) { - init_video_codec(this, codec_type); - init_postprocess(this); - this->decoder_init_mode = 0; - } -} - -static void ff_handle_header_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - - lprintf ("header buffer\n"); - - /* accumulate data */ - ff_check_bufsize(this, this->size + buf->size); - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - int codec_type; - - lprintf ("header complete\n"); - codec_type = buf->type & 0xFFFF0000; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - - lprintf("standard header\n"); - - /* init package containing bih */ - memcpy ( &this->bih, this->buf, sizeof(xine_bmiheader) ); - - if (this->bih.biSize > sizeof(xine_bmiheader)) { - this->context->extradata_size = this->bih.biSize - sizeof(xine_bmiheader); - this->context->extradata = malloc(this->context->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, this->buf + sizeof(xine_bmiheader), - this->context->extradata_size); - } - - this->context->bits_per_sample = this->bih.biBitCount; - - } else { - - switch (codec_type) { - case BUF_VIDEO_RV10: - case BUF_VIDEO_RV20: - this->bih.biWidth = BE_16(&this->buf[12]); - this->bih.biHeight = BE_16(&this->buf[14]); - - this->context->sub_id = BE_32(&this->buf[30]); - - this->context->slice_offset = xine_xmalloc(sizeof(int)*SLICE_OFFSET_SIZE); - this->slice_offset_size = SLICE_OFFSET_SIZE; - - lprintf("w=%d, h=%d\n", this->bih.biWidth, this->bih.biHeight); - - break; - default: - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_video_dec: unknown header for buf type 0x%X\n", codec_type); - return; - } - } - - /* reset accumulator */ - this->size = 0; - } -} - -static void ff_handle_special_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - /* take care of all the various types of special buffers - * note that order is important here */ - lprintf("special buffer\n"); - - if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM && - !this->context->extradata_size) { - - lprintf("BUF_SPECIAL_STSD_ATOM\n"); - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = xine_xmalloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); - - } else if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG && - !this->context->extradata_size) { - - lprintf("BUF_SPECIAL_DECODER_CONFIG\n"); - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = xine_xmalloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); - - } else if (buf->decoder_info[1] == BUF_SPECIAL_PALETTE) { - unsigned int i; - - palette_entry_t *demuxer_palette; - AVPaletteControl *decoder_palette; - - lprintf("BUF_SPECIAL_PALETTE\n"); - this->context->palctrl = &this->palette_control; - decoder_palette = (AVPaletteControl *)this->context->palctrl; - demuxer_palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - - for (i = 0; i < buf->decoder_info[2]; i++) { - decoder_palette->palette[i] = - (demuxer_palette[i].r << 16) | - (demuxer_palette[i].g << 8) | - (demuxer_palette[i].b << 0); - } - decoder_palette->palette_changed = 1; - - } else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) { - int i; - - lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n"); - this->context->slice_count = buf->decoder_info[2]+1; - - lprintf("slice_count=%d\n", this->context->slice_count); - - if(this->context->slice_count > this->slice_offset_size) { - this->context->slice_offset = realloc(this->context->slice_offset, - sizeof(int)*this->context->slice_count); - this->slice_offset_size = this->context->slice_count; - } - - for(i = 0; i < this->context->slice_count; i++) { - this->context->slice_offset[i] = - ((uint32_t *) buf->decoder_info_ptr[2])[(2*i)+1]; - lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]); - } - } -} - -static void ff_handle_mpeg12_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - - vo_frame_t *img; - int free_img; - int got_picture, len; - int offset = 0; - int flush = 0; - int size = buf->size; - - lprintf("handle_mpeg12_buffer\n"); - - while ((size > 0) || (flush == 1)) { - - uint8_t *current; - int next_flush; - - got_picture = 0; - if (!flush) { - current = mpeg_parser_decode_data(this->mpeg_parser, - buf->content + offset, buf->content + offset + size, - &next_flush); - } else { - current = buf->content + offset + size; /* end of the buffer */ - next_flush = 0; - } - if (current == NULL) { - lprintf("current == NULL\n"); - return; - } - - if (this->mpeg_parser->has_sequence) { - ff_handle_mpeg_sequence(this, this->mpeg_parser); - } - - if (!this->decoder_ok) - return; - - if (flush) { - lprintf("flush lavc buffers\n"); - /* hack: ffmpeg outputs the last frame if size=0 */ - this->mpeg_parser->buffer_size = 0; - } - - /* skip decoding b frames if too late */ - this->context->hurry_up = (this->skipframes > 0); - - lprintf("avcodec_decode_video: size=%d\n", this->mpeg_parser->buffer_size); - len = avcodec_decode_video (this->context, this->av_frame, - &got_picture, this->mpeg_parser->chunk_buffer, - this->mpeg_parser->buffer_size); - lprintf("avcodec_decode_video: decoded_size=%d, got_picture=%d\n", - len, got_picture); - len = current - buf->content - offset; - lprintf("avcodec_decode_video: consumed_size=%d\n", len); - - flush = next_flush; - - if ((len < 0) || (len > buf->size)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_video_dec: error decompressing frame\n"); - size = 0; /* draw a bad frame and exit */ - } else { - size -= len; - offset += len; - } - - if (got_picture && this->av_frame->data[0]) { - /* got a picture, draw it */ - if(!this->av_frame->opaque) { - /* indirect rendering */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->bih.biWidth, - this->bih.biHeight, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - free_img = 1; - } else { - /* DR1 */ - img = (vo_frame_t*) this->av_frame->opaque; - free_img = 0; - } - - img->pts = this->pts; - this->pts = 0; - - if (this->av_frame->repeat_pict) - img->duration = this->video_step * 3 / 2; - else - img->duration = this->video_step; - - img->crop_right = this->crop_right; - img->crop_bottom = this->crop_bottom; - - this->skipframes = img->draw(img, this->stream); - - if(free_img) - img->free(img); - - } else { - - if (this->context->hurry_up) { - /* skipped frame, output a bad frame */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->bih.biWidth, - this->bih.biHeight, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - img->pts = 0; - img->duration = this->video_step; - img->bad_frame = 1; - this->skipframes = img->draw(img, this->stream); - img->free(img); - } - } - } -} - -static void ff_handle_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - uint8_t *chunk_buf = this->buf; - AVRational avr00 = {0, 1}; - - lprintf("handle_buffer\n"); - - if (!this->decoder_ok) { - if (this->decoder_init_mode) { - int codec_type = buf->type & 0xFFFF0000; - - /* init ffmpeg decoder */ - init_video_codec(this, codec_type); - init_postprocess(this); - this->decoder_init_mode = 0; - } else { - return; - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAME_START) { - lprintf("BUF_FLAG_FRAME_START\n"); - this->size = 0; - } - - /* data accumulation */ - if (buf->size > 0) { - if ((this->size == 0) && - ((buf->size + FF_INPUT_BUFFER_PADDING_SIZE) < buf->max_size) && - (buf->decoder_flags & BUF_FLAG_FRAME_END)) { - /* buf contains a complete frame */ - /* no memcpy needed */ - chunk_buf = buf->content; - this->size = buf->size; - lprintf("no memcpy needed to accumulate data\n"); - } else { - /* copy data into our internal buffer */ - ff_check_bufsize(this, this->size + buf->size); - chunk_buf = this->buf; /* ff_check_bufsize might realloc this->buf */ - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - lprintf("accumulate data into this->buf\n"); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - vo_frame_t *img; - int free_img; - int got_picture, len; - int got_one_picture = 0; - int offset = 0; - int codec_type = buf->type & 0xFFFF0000; - - /* pad input data */ - /* note: bitstream, alt bitstream reader or something will cause - * severe mpeg4 artifacts if padding is less than 32 bits. - */ - memset(&chunk_buf[this->size], 0, FF_INPUT_BUFFER_PADDING_SIZE); - - while (this->size > 0) { - - /* DV frames can be completely skipped */ - if( codec_type == BUF_VIDEO_DV && this->skipframes ) { - this->size = 0; - got_picture = 0; - } else { - /* skip decoding b frames if too late */ - this->context->hurry_up = (this->skipframes > 0); - - lprintf("buffer size: %d\n", this->size); - len = avcodec_decode_video (this->context, this->av_frame, - &got_picture, &chunk_buf[offset], - this->size); - lprintf("consumed size: %d, got_picture: %d\n", len, got_picture); - if ((len <= 0) || (len > this->size)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_video_dec: error decompressing frame\n"); - this->size = 0; - - } else { - - offset += len; - this->size -= len; - - if (this->size > 0) { - ff_check_bufsize(this, this->size); - memmove (this->buf, &chunk_buf[offset], this->size); - chunk_buf = this->buf; - } - } - } - - /* aspect ratio provided by ffmpeg, override previous setting */ - if ((this->aspect_ratio_prio < 2) && - av_cmp_q(this->context->sample_aspect_ratio, avr00)) { - - this->aspect_ratio = av_q2d(this->context->sample_aspect_ratio) * - (double)this->bih.biWidth / (double)this->bih.biHeight; - this->aspect_ratio_prio = 2; - lprintf("ffmpeg aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - - if (got_picture && this->av_frame->data[0]) { - /* got a picture, draw it */ - got_one_picture = 1; - if(!this->av_frame->opaque) { - /* indirect rendering */ - - /* initialize the colorspace converter */ - if (!this->cs_convert_init) { - if ((this->context->pix_fmt == PIX_FMT_RGBA32) || - (this->context->pix_fmt == PIX_FMT_RGB565) || - (this->context->pix_fmt == PIX_FMT_RGB555) || - (this->context->pix_fmt == PIX_FMT_BGR24) || - (this->context->pix_fmt == PIX_FMT_RGB24) || - (this->context->pix_fmt == PIX_FMT_PAL8)) { - this->output_format = XINE_IMGFMT_YUY2; - init_yuv_planes(&this->yuv, this->bih.biWidth, this->bih.biHeight); - this->yuv_init = 1; - } - this->cs_convert_init = 1; - } - - if (this->aspect_ratio_prio == 0) { - this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight; - this->aspect_ratio_prio = 1; - lprintf("default aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->bih.biWidth, - this->bih.biHeight, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - free_img = 1; - } else { - /* DR1 */ - img = (vo_frame_t*) this->av_frame->opaque; - free_img = 0; - } - - /* post processing */ - if(this->pp_quality != this->class->pp_quality) - pp_change_quality(this); - - if(this->pp_available && this->pp_quality) { - - if(this->av_frame->opaque) { - /* DR1 */ - img = this->stream->video_out->get_frame (this->stream->video_out, - img->width, - img->height, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - free_img = 1; - } - - pp_postprocess(this->av_frame->data, this->av_frame->linesize, - img->base, img->pitches, - img->width, img->height, - this->av_frame->qscale_table, this->av_frame->qstride, - this->pp_mode, this->pp_context, - this->av_frame->pict_type); - - } else if (!this->av_frame->opaque) { - /* colorspace conversion or copy */ - ff_convert_frame(this, img); - } - - img->pts = this->pts; - this->pts = 0; - - /* workaround for weird 120fps streams */ - if( this->video_step == 750 ) { - /* fallback to the VIDEO_PTS_MODE */ - this->video_step = 0; - } - - if (this->av_frame->repeat_pict) - img->duration = this->video_step * 3 / 2; - else - img->duration = this->video_step; - - img->crop_right = this->crop_right; - img->crop_bottom = this->crop_bottom; - - this->skipframes = img->draw(img, this->stream); - - if(free_img) - img->free(img); - } - } - - if (!got_one_picture) { - /* skipped frame, output a bad frame */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->bih.biWidth, - this->bih.biHeight, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - img->pts = 0; - img->duration = this->video_step; - img->bad_frame = 1; - this->skipframes = img->draw(img, this->stream); - img->free(img); - } - } -} - -static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("processing packet type = %08x, len = %d, decoder_flags=%08x\n", - buf->type, buf->size, buf->decoder_flags); - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - - ff_handle_preview_buffer(this, buf); - - } else { - - if (buf->decoder_flags & BUF_FLAG_SPECIAL) { - - ff_handle_special_buffer(this, buf); - - } - - if (buf->decoder_flags & BUF_FLAG_HEADER) { - - ff_handle_header_buffer(this, buf); - - if (buf->decoder_flags & BUF_FLAG_ASPECT) { - if (this->aspect_ratio_prio < 3) { - this->aspect_ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2]; - this->aspect_ratio_prio = 3; - lprintf("aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - } - - } else { - - /* decode */ - if (buf->pts) - this->pts = buf->pts; - - if (this->is_mpeg12) { - ff_handle_mpeg12_buffer(this, buf); - } else { - ff_handle_buffer(this, buf); - } - - } - } -} - -static void ff_flush (video_decoder_t *this_gen) { - lprintf ("ff_flush\n"); -} - -static void ff_reset (video_decoder_t *this_gen) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("ff_reset\n"); - - this->size = 0; - - if(this->context && this->decoder_ok) - avcodec_flush_buffers(this->context); - - if (this->is_mpeg12) - mpeg_parser_reset(this->mpeg_parser); -} - -static void ff_discontinuity (video_decoder_t *this_gen) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("ff_discontinuity\n"); - this->pts = 0; -} - -static void ff_dispose (video_decoder_t *this_gen) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("ff_dispose\n"); - - if (this->decoder_ok) { - xine_list_iterator_t it; - AVFrame *av_frame; - - pthread_mutex_lock(&ffmpeg_lock); - avcodec_close (this->context); - pthread_mutex_unlock(&ffmpeg_lock); - - /* frame garbage collector here - workaround for buggy ffmpeg codecs that - * don't release their DR1 frames */ - while( (it = xine_list_front(this->dr1_frames)) != NULL ) - { - av_frame = (AVFrame *)xine_list_get_value(this->dr1_frames, it); - release_buffer(this->context, av_frame); - } - - this->stream->video_out->close(this->stream->video_out, this->stream); - this->decoder_ok = 0; - } - - if(this->context && this->context->slice_offset) - free(this->context->slice_offset); - - if(this->context && this->context->extradata) - free(this->context->extradata); - - if(this->yuv_init) - free_yuv_planes(&this->yuv); - - if( this->context ) - free( this->context ); - - if( this->av_frame ) - free( this->av_frame ); - - if (this->buf) - free(this->buf); - this->buf = NULL; - - if(this->pp_context) - pp_free_context(this->pp_context); - - if(this->pp_mode) - pp_free_mode(this->pp_mode); - - mpeg_parser_dispose(this->mpeg_parser); - - xine_list_delete(this->dr1_frames); - - free (this_gen); -} - -static video_decoder_t *ff_video_open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - ff_video_decoder_t *this ; - - lprintf ("open_plugin\n"); - - this = (ff_video_decoder_t *) xine_xmalloc (sizeof (ff_video_decoder_t)); - - this->video_decoder.decode_data = ff_decode_data; - this->video_decoder.flush = ff_flush; - this->video_decoder.reset = ff_reset; - this->video_decoder.discontinuity = ff_discontinuity; - this->video_decoder.dispose = ff_dispose; - this->size = 0; - - this->stream = stream; - this->class = (ff_video_class_t *) class_gen; - - this->av_frame = avcodec_alloc_frame(); - this->context = avcodec_alloc_context(); - this->context->opaque = this; - this->context->palctrl = NULL; - - this->decoder_ok = 0; - this->decoder_init_mode = 1; - this->buf = xine_xmalloc(VIDEOBUFSIZE + FF_INPUT_BUFFER_PADDING_SIZE); - this->bufsize = VIDEOBUFSIZE; - - this->is_mpeg12 = 0; - this->aspect_ratio = 0; - - this->pp_quality = 0; - this->pp_context = NULL; - this->pp_mode = NULL; - - this->mpeg_parser = NULL; - - this->dr1_frames = xine_list_new(); - - return &this->video_decoder; -} - -static char *ff_video_get_identifier (video_decoder_class_t *this) { - return "ffmpeg video"; -} - -static char *ff_video_get_description (video_decoder_class_t *this) { - return "ffmpeg based video decoder plugin"; -} - -static void ff_video_dispose_class (video_decoder_class_t *this) { - free (this); -} - -void *init_video_plugin (xine_t *xine, void *data) { - - ff_video_class_t *this; - config_values_t *config; - - this = (ff_video_class_t *) xine_xmalloc (sizeof (ff_video_class_t)); - - this->decoder_class.open_plugin = ff_video_open_plugin; - this->decoder_class.get_identifier = ff_video_get_identifier; - this->decoder_class.get_description = ff_video_get_description; - this->decoder_class.dispose = ff_video_dispose_class; - this->xine = xine; - - pthread_once( &once_control, init_once_routine ); - - /* Configuration for post processing quality - default to mid (3) for the - * moment */ - config = xine->config; - - this->pp_quality = xine->config->register_range(config, "video.processing.ffmpeg_pp_quality", 3, - 0, PP_QUALITY_MAX, - _("MPEG-4 postprocessing quality"), - _("You can adjust the amount of post processing applied to MPEG-4 video.\n" - "Higher values result in better quality, but need more CPU. Lower values may " - "result in image defects like block artifacts. For high quality content, " - "too heavy post processing can actually make the image worse by blurring it " - "too much."), - 10, pp_quality_cb, this); - - return this; -} - -static uint32_t supported_video_types[] = { - #ifdef CONFIG_MSMPEG4V1_DECODER - BUF_VIDEO_MSMPEG4_V1, - #endif - #ifdef CONFIG_MSMPEG4V2_DECODER - BUF_VIDEO_MSMPEG4_V2, - #endif - #ifdef CONFIG_MSMPEG4V3_DECODER - BUF_VIDEO_MSMPEG4_V3, - #endif - #ifdef CONFIG_WMV1_DECODER - BUF_VIDEO_WMV7, - #endif - #ifdef CONFIG_WMV2_DECODER - BUF_VIDEO_WMV8, - #endif - #ifdef CONFIG_WMV3_DECODER - BUF_VIDEO_WMV9, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_MPEG4, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_XVID, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_DIVX5, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_3IVX, - #endif - #ifdef CONFIG_MJPEG_DECODER - BUF_VIDEO_JPEG, - #endif - #ifdef CONFIG_MJPEG_DECODER - BUF_VIDEO_MJPEG, - #endif - #ifdef CONFIG_MJPEGB_DECODER - BUF_VIDEO_MJPEG_B, - #endif - #ifdef CONFIG_H263I_DECODER - BUF_VIDEO_I263, - #endif - #ifdef CONFIG_H263_DECODER - BUF_VIDEO_H263, - #endif - #ifdef CONFIG_RV10_DECODER - BUF_VIDEO_RV10, - #endif - #ifdef CONFIG_RV20_DECODER - BUF_VIDEO_RV20, - #endif - #ifdef CONFIG_INDEO3_DECODER - BUF_VIDEO_IV31, - #endif - #ifdef CONFIG_INDEO3_DECODER - BUF_VIDEO_IV32, - #endif - #ifdef CONFIG_SVQ1_DECODER - BUF_VIDEO_SORENSON_V1, - #endif - #ifdef CONFIG_SVQ3_DECODER - BUF_VIDEO_SORENSON_V3, - #endif - #ifdef CONFIG_DVVIDEO_DECODER - BUF_VIDEO_DV, - #endif - #ifdef CONFIG_HUFFYUV_DECODER - BUF_VIDEO_HUFFYUV, - #endif - #ifdef CONFIG_VP3_DECODER - BUF_VIDEO_VP31, - #endif - #ifdef CONFIG_VP5_DECODER - BUF_VIDEO_VP5, - #endif - #ifdef CONFIG_VP6_DECODER - BUF_VIDEO_VP6, - BUF_VIDEO_VP6F, - #endif - #ifdef CONFIG_4XM_DECODER - BUF_VIDEO_4XM, - #endif - #ifdef CONFIG_CINEPAK_DECODER - BUF_VIDEO_CINEPAK, - #endif - #ifdef CONFIG_MSVIDEO1_DECODER - BUF_VIDEO_MSVC, - #endif - #ifdef CONFIG_MSRLE_DECODER - BUF_VIDEO_MSRLE, - #endif - #ifdef CONFIG_RPZA_DECODER - BUF_VIDEO_RPZA, - #endif - #ifdef CONFIG_CYUV_DECODER - BUF_VIDEO_CYUV, - #endif - #ifdef CONFIG_ROQ_DECODER - BUF_VIDEO_ROQ, - #endif - #ifdef CONFIG_IDCIN_DECODER - BUF_VIDEO_IDCIN, - #endif - #ifdef CONFIG_XAN_WC3_DECODER - BUF_VIDEO_WC3, - #endif - #ifdef CONFIG_WS_VQA_DECODER - BUF_VIDEO_VQA, - #endif - #ifdef CONFIG_INTERPLAY_VIDEO_DECODER - BUF_VIDEO_INTERPLAY, - #endif - #ifdef CONFIG_FLIC_DECODER - BUF_VIDEO_FLI, - #endif - #ifdef CONFIG_8BPS_DECODER - BUF_VIDEO_8BPS, - #endif - #ifdef CONFIG_SMC_DECODER - BUF_VIDEO_SMC, - #endif - #ifdef CONFIG_TRUEMOTION1_DECODER - BUF_VIDEO_DUCKTM1, - #endif - #ifdef CONFIG_TRUEMOTION2_DECODER - BUF_VIDEO_DUCKTM2, - #endif - #ifdef CONFIG_VMDVIDEO_DECODER - BUF_VIDEO_VMD, - #endif - #ifdef CONFIG_ZLIB_DECODER - BUF_VIDEO_ZLIB, - #endif - #ifdef CONFIG_MSZH_DECODER - BUF_VIDEO_MSZH, - #endif - #ifdef CONFIG_ASV1_DECODER - BUF_VIDEO_ASV1, - #endif - #ifdef CONFIG_ASV2_DECODER - BUF_VIDEO_ASV2, - #endif - #ifdef CONFIG_VCR1_DECODER - BUF_VIDEO_ATIVCR1, - #endif - #ifdef CONFIG_FLV_DECODER - BUF_VIDEO_FLV1, - #endif - #ifdef CONFIG_QTRLE_DECODER - BUF_VIDEO_QTRLE, - #endif - #ifdef CONFIG_H264_DECODER - BUF_VIDEO_H264, - #endif - #ifdef CONFIG_H261_DECODER - BUF_VIDEO_H261, - #endif - #ifdef CONFIG_AASC_DECODER - BUF_VIDEO_AASC, - #endif - #ifdef CONFIG_LOCO_DECODER - BUF_VIDEO_LOCO, - #endif - #ifdef CONFIG_QDRAW_DECODER - BUF_VIDEO_QDRW, - #endif - #ifdef CONFIG_QPEG_DECODER - BUF_VIDEO_QPEG, - #endif - #ifdef CONFIG_TSCC_DECODER - BUF_VIDEO_TSCC, - #endif - #ifdef CONFIG_ULTI_DECODER - BUF_VIDEO_ULTI, - #endif - #ifdef CONFIG_WNV1_DECODER - BUF_VIDEO_WNV1, - #endif - #ifdef CONFIG_VIXL_DECODER - BUF_VIDEO_XL, - #endif - #ifdef CONFIG_INDEO2_DECODER - BUF_VIDEO_RT21, - #endif - #ifdef CONFIG_FRAPS_DECODER - BUF_VIDEO_FPS1, - #endif - #ifdef CONFIG_MPEG1VIDEO_DECODER - BUF_VIDEO_MPEG, - #endif - #ifdef CONFIG_CSCD_DECODER - BUF_VIDEO_CSCD, - #endif - #ifdef CONFIG_AVS_DECODER - BUF_VIDEO_AVS, - #endif - #ifdef CONFIG_MMVIDEO_DECODER - BUF_VIDEO_ALGMM, - #endif - #ifdef CONFIG_ZMBV_DECODER - BUF_VIDEO_ZMBV, - #endif - #ifdef CONFIG_SMACKVIDEO_DECODER - BUF_VIDEO_SMACKER, - #endif - #ifdef CONFIG_NUV_DECODER - BUF_VIDEO_NUV, - #endif - #ifdef CONFIG_KMVC_DECODER - BUF_VIDEO_KMVC, - #endif - #ifdef CONFIG_FLASHSV_DECODER - BUF_VIDEO_FLASHSV, - #endif - #ifdef CONFIG_CAVS_DECODER - BUF_VIDEO_CAVS, - #endif - - 0 -}; - -static uint32_t wmv8_video_types[] = { - BUF_VIDEO_WMV8, - 0 -}; - -static uint32_t wmv9_video_types[] = { - BUF_VIDEO_WMV9, - 0 -}; - -decoder_info_t dec_info_ffmpeg_video = { - supported_video_types, /* supported types */ - 6 /* priority */ -}; - -decoder_info_t dec_info_ffmpeg_wmv8 = { - wmv8_video_types, /* supported types */ - 0 /* priority */ -}; - -decoder_info_t dec_info_ffmpeg_wmv9 = { - wmv9_video_types, /* supported types */ - 0 /* priority */ -}; diff --git a/src/libffmpeg/xine_decoder.c b/src/libffmpeg/xine_decoder.c deleted file mode 100644 index 2eeb9746b..000000000 --- a/src/libffmpeg/xine_decoder.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (C) 2001-2004 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.173 2007/01/13 21:19:52 miguelfreitas Exp $ - * - * xine decoder plugin using ffmpeg - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "ffmpeg_config.h" -#endif - -#include "xine_internal.h" - -#include "xine_decoder.h" - -/* - * common initialisation - */ - -pthread_once_t once_control = PTHREAD_ONCE_INIT; -pthread_mutex_t ffmpeg_lock; - -#ifndef HAVE_FFMPEG - -#define REGISTER_ENCODER(X,x) \ - if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder) -#define REGISTER_DECODER(X,x) \ - if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder) -#define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x) - -#define REGISTER_PARSER(X,x) \ - if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser) - -/* If you do not call this function, then you can select exactly which - formats you want to support */ - -/** - * simple call to register all the codecs. - */ -void avcodec_register_all(void) -{ - static int inited = 0; - - if (inited != 0) - return; - inited = 1; - - /* video codecs */ - REGISTER_DECODER(AASC, aasc); - REGISTER_ENCDEC (ASV1, asv1); - REGISTER_ENCDEC (ASV2, asv2); - REGISTER_DECODER(AVS, avs); - REGISTER_DECODER(BMP, bmp); - REGISTER_DECODER(CAVS, cavs); - REGISTER_DECODER(CINEPAK, cinepak); - REGISTER_DECODER(CLJR, cljr); - REGISTER_DECODER(CSCD, cscd); - REGISTER_DECODER(CYUV, cyuv); - REGISTER_DECODER(DSICINVIDEO, dsicinvideo); - REGISTER_ENCDEC (DVVIDEO, dvvideo); - REGISTER_DECODER(EIGHTBPS, eightbps); - REGISTER_ENCDEC (FFV1, ffv1); - REGISTER_ENCDEC (FFVHUFF, ffvhuff); - REGISTER_DECODER(FLASHSV, flashsv); - REGISTER_DECODER(FLIC, flic); - REGISTER_ENCDEC (FLV, flv); - REGISTER_DECODER(FOURXM, fourxm); - REGISTER_DECODER(FRAPS, fraps); - REGISTER_ENCDEC (GIF, gif); - REGISTER_ENCDEC (H261, h261); - REGISTER_ENCDEC (H263, h263); - REGISTER_DECODER(H263I, h263i); - REGISTER_ENCODER(H263P, h263p); - REGISTER_DECODER(H264, h264); - REGISTER_ENCDEC (HUFFYUV, huffyuv); - REGISTER_DECODER(IDCIN, idcin); - REGISTER_DECODER(INDEO2, indeo2); - REGISTER_DECODER(INDEO3, indeo3); - REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video); - REGISTER_ENCODER(JPEGLS, jpegls); - REGISTER_DECODER(KMVC, kmvc); - REGISTER_ENCODER(LJPEG, ljpeg); - REGISTER_DECODER(LOCO, loco); - REGISTER_DECODER(MDEC, mdec); - REGISTER_ENCDEC (MJPEG, mjpeg); - REGISTER_DECODER(MJPEGB, mjpegb); - REGISTER_DECODER(MMVIDEO, mmvideo); -#ifdef HAVE_XVMC - REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc); -#endif - REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); - REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); - REGISTER_ENCDEC (MPEG4, mpeg4); - REGISTER_DECODER(MPEGVIDEO, mpegvideo); - REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); - REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); - REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); - REGISTER_DECODER(MSRLE, msrle); - REGISTER_DECODER(MSVIDEO1, msvideo1); - REGISTER_DECODER(MSZH, mszh); - REGISTER_DECODER(NUV, nuv); - REGISTER_ENCODER(PAM, pam); - REGISTER_ENCODER(PBM, pbm); - REGISTER_ENCODER(PGM, pgm); - REGISTER_ENCODER(PGMYUV, pgmyuv); -#ifdef CONFIG_ZLIB - REGISTER_ENCDEC (PNG, png); -#endif - REGISTER_ENCODER(PPM, ppm); - REGISTER_DECODER(QDRAW, qdraw); - REGISTER_DECODER(QPEG, qpeg); - REGISTER_DECODER(QTRLE, qtrle); - REGISTER_ENCDEC (RAWVIDEO, rawvideo); - REGISTER_DECODER(ROQ, roq); - REGISTER_DECODER(RPZA, rpza); - REGISTER_ENCDEC (RV10, rv10); - REGISTER_ENCDEC (RV20, rv20); - REGISTER_DECODER(SMACKER, smacker); - REGISTER_DECODER(SMC, smc); - REGISTER_ENCDEC (SNOW, snow); - REGISTER_DECODER(SP5X, sp5x); - REGISTER_ENCDEC (SVQ1, svq1); - REGISTER_DECODER(SVQ3, svq3); - REGISTER_DECODER(TARGA, targa); - REGISTER_DECODER(THEORA, theora); - REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo); - REGISTER_DECODER(TIFF, tiff); - REGISTER_DECODER(TRUEMOTION1, truemotion1); - REGISTER_DECODER(TRUEMOTION2, truemotion2); - REGISTER_DECODER(TSCC, tscc); - REGISTER_DECODER(ULTI, ulti); - REGISTER_DECODER(VC1, vc1); - REGISTER_DECODER(VCR1, vcr1); - REGISTER_DECODER(VMDVIDEO, vmdvideo); - REGISTER_DECODER(VMNC, vmnc); - REGISTER_DECODER(VP3, vp3); - REGISTER_DECODER(VP5, vp5); - REGISTER_DECODER(VP6, vp6); - REGISTER_DECODER(VP6F, vp6f); - REGISTER_DECODER(VQA, vqa); - REGISTER_ENCDEC (WMV1, wmv1); - REGISTER_ENCDEC (WMV2, wmv2); - REGISTER_DECODER(WMV3, wmv3); - REGISTER_DECODER(WNV1, wnv1); -#ifdef CONFIG_X264 - REGISTER_ENCODER(X264, x264); -#endif - REGISTER_DECODER(XAN_WC3, xan_wc3); - REGISTER_DECODER(XL, xl); -#ifdef CONFIG_XVID - REGISTER_ENCODER(XVID, xvid); -#endif - REGISTER_ENCDEC (ZLIB, zlib); -#ifdef CONFIG_ZLIB - REGISTER_ENCDEC (ZMBV, zmbv); -#endif - - /* audio codecs */ -#ifdef CONFIG_LIBFAAD - REGISTER_DECODER(AAC, aac); - REGISTER_DECODER(MPEG4AAC, mpeg4aac); -#endif -#ifdef CONFIG_LIBA52 - REGISTER_DECODER(AC3, ac3); -#endif - REGISTER_ENCODER(AC3, ac3); - REGISTER_DECODER(ALAC, alac); -#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) - REGISTER_ENCDEC (AMR_NB, amr_nb); -#endif -#ifdef CONFIG_AMR_WB - REGISTER_ENCDEC (AMR_WB, amr_wb); -#endif - REGISTER_DECODER(COOK, cook); - REGISTER_DECODER(DSICINAUDIO, dsicinaudio); -#ifdef CONFIG_LIBDTS - REGISTER_DECODER(DTS, dts); -#endif -#ifdef CONFIG_LIBFAAC - REGISTER_ENCODER(FAAC, faac); -#endif - REGISTER_ENCDEC (FLAC, flac); - REGISTER_DECODER(IMC, imc); -#ifdef CONFIG_LIBGSM - REGISTER_ENCDEC (LIBGSM, libgsm); -#endif - REGISTER_DECODER(MACE3, mace3); - REGISTER_DECODER(MACE6, mace6); - REGISTER_ENCDEC (MP2, mp2); - REGISTER_DECODER(MP3, mp3); - REGISTER_DECODER(MP3ADU, mp3adu); -#ifdef CONFIG_LIBMP3LAME - REGISTER_ENCODER(MP3LAME, mp3lame); -#endif - REGISTER_DECODER(MP3ON4, mp3on4); - REGISTER_DECODER(MPC7, mpc7); -#ifdef CONFIG_LIBVORBIS - if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis); - if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis); -#endif - REGISTER_DECODER(QDM2, qdm2); - REGISTER_DECODER(RA_144, ra_144); - REGISTER_DECODER(RA_288, ra_288); - REGISTER_DECODER(SHORTEN, shorten); - REGISTER_DECODER(SMACKAUD, smackaud); - REGISTER_ENCDEC (SONIC, sonic); - REGISTER_ENCODER(SONIC_LS, sonic_ls); - REGISTER_DECODER(TRUESPEECH, truespeech); - REGISTER_DECODER(TTA, tta); - REGISTER_DECODER(VMDAUDIO, vmdaudio); - REGISTER_ENCDEC (VORBIS, vorbis); - REGISTER_DECODER(WAVPACK, wavpack); - REGISTER_DECODER(WMAV1, wmav1); - REGISTER_DECODER(WMAV2, wmav2); - REGISTER_DECODER(WS_SND1, ws_snd1); - - /* pcm codecs */ - REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); - REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); - REGISTER_ENCDEC (PCM_S8, pcm_s8); - REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); - REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); - REGISTER_ENCDEC (PCM_S24BE, pcm_s24be); - REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud); - REGISTER_ENCDEC (PCM_S24LE, pcm_s24le); - REGISTER_ENCDEC (PCM_S32BE, pcm_s32be); - REGISTER_ENCDEC (PCM_S32LE, pcm_s32le); - REGISTER_ENCDEC (PCM_U8, pcm_u8); - REGISTER_ENCDEC (PCM_U16BE, pcm_u16be); - REGISTER_ENCDEC (PCM_U16LE, pcm_u16le); - REGISTER_ENCDEC (PCM_U24BE, pcm_u24be); - REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); - REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); - REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); - - /* dpcm codecs */ - REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm); - REGISTER_DECODER(ROQ_DPCM, roq_dpcm); - REGISTER_DECODER(SOL_DPCM, sol_dpcm); - REGISTER_DECODER(XAN_DPCM, xan_dpcm); - - /* adpcm codecs */ - REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm); - REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx); - REGISTER_ENCDEC (ADPCM_CT, adpcm_ct); - REGISTER_ENCDEC (ADPCM_EA, adpcm_ea); - REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); - REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3); - REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4); - REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt); - REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); - REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); - REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws); - REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); - REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2); - REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3); - REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4); - REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf); - REGISTER_ENCDEC (ADPCM_XA, adpcm_xa); - REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha); - - /* subtitles */ - REGISTER_ENCDEC (DVBSUB, dvbsub); - REGISTER_ENCDEC (DVDSUB, dvdsub); - - /* parsers */ - REGISTER_PARSER (AAC, aac); - REGISTER_PARSER (AC3, ac3); - REGISTER_PARSER (CAVSVIDEO, cavsvideo); - REGISTER_PARSER (DVBSUB, dvbsub); - REGISTER_PARSER (DVDSUB, dvdsub); - REGISTER_PARSER (H261, h261); - REGISTER_PARSER (H263, h263); - REGISTER_PARSER (H264, h264); - REGISTER_PARSER (MJPEG, mjpeg); - REGISTER_PARSER (MPEG4VIDEO, mpeg4video); - REGISTER_PARSER (MPEGAUDIO, mpegaudio); - REGISTER_PARSER (MPEGVIDEO, mpegvideo); - REGISTER_PARSER (PNM, pnm); - - /* - av_register_bitstream_filter(&dump_extradata_bsf); - av_register_bitstream_filter(&remove_extradata_bsf); - av_register_bitstream_filter(&noise_bsf); - av_register_bitstream_filter(&mp3_header_compress_bsf); - av_register_bitstream_filter(&mp3_header_decompress_bsf); - av_register_bitstream_filter(&mjpega_dump_header_bsf); - */ -} - -#endif - -void init_once_routine(void) { - pthread_mutex_init(&ffmpeg_lock, NULL); - avcodec_init(); - avcodec_register_all(); -} - -/* - * exported plugin catalog entry - */ - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER | PLUGIN_MUST_PRELOAD, 18, "ffmpegvideo", XINE_VERSION_CODE, &dec_info_ffmpeg_video, init_video_plugin }, - { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv8", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv8, init_video_plugin }, - { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv9", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv9, init_video_plugin }, - { PLUGIN_AUDIO_DECODER, 15, "ffmpegaudio", XINE_VERSION_CODE, &dec_info_ffmpeg_audio, init_audio_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libffmpeg/xine_decoder.h b/src/libffmpeg/xine_decoder.h deleted file mode 100644 index 879ee3175..000000000 --- a/src/libffmpeg/xine_decoder.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2001-2005 the xine project - * - * This file is part of xine, a free 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: xine_decoder.h,v 1.7 2006/08/02 07:15:27 tmmm Exp $ - * - */ - -#ifndef HAVE_XINE_DECODER_H -#define HAVE_XINE_DECODER_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_FFMPEG -# include -#else -# include "libavcodec/avcodec.h" -#endif - -typedef struct ff_codec_s { - uint32_t type; - enum CodecID id; - const char *name; -} ff_codec_t; - -void *init_audio_plugin (xine_t *xine, void *data); -void *init_video_plugin (xine_t *xine, void *data); - -extern decoder_info_t dec_info_ffmpeg_video; -extern decoder_info_t dec_info_ffmpeg_wmv8; -extern decoder_info_t dec_info_ffmpeg_wmv9; -extern decoder_info_t dec_info_ffmpeg_audio; - -extern pthread_once_t once_control; -void init_once_routine(void); - -extern pthread_mutex_t ffmpeg_lock; - -#endif diff --git a/src/libffmpeg/xine_encoder.c b/src/libffmpeg/xine_encoder.c deleted file mode 100644 index e234b4ddc..000000000 --- a/src/libffmpeg/xine_encoder.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (C) 2000-2004 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: xine_encoder.c,v 1.25 2006/07/10 22:08:29 dgp85 Exp $ - */ - -/* mpeg encoders for the dxr3 video out plugin. */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "dxr3_mpeg_encoder" -/* #define LOG_VERBOSE */ -/* #define LOG */ - -#include "video_out_dxr3.h" - -#ifdef HAVE_FFMPEG -# include -#else -# include "libavcodec/avcodec.h" -#endif - -/* buffer size for encoded mpeg1 stream; will hold one intra frame - * at 640x480 typical sizes are <50 kB. 512 kB should be plenty */ -#define DEFAULT_BUFFER_SIZE 512*1024 - - -/*initialisation function, used by the dxr3 plugin */ -int dxr3_encoder_init(dxr3_driver_t *drv) EXPORTED; - -/* functions required by encoder api */ -static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame); -static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame); -static int lavc_on_unneeded(dxr3_driver_t *drv); - -/*encoder structure*/ -typedef struct lavc_data_s { - encoder_data_t encoder_data; - AVCodecContext *context; /* handle for encoding */ - int width, height; /* width and height of the video frame */ - uint8_t *ffmpeg_buffer; /* lavc buffer */ - AVFrame *picture; /* picture to be encoded */ - uint8_t *out[3]; /* aligned buffer for YV12 data */ - uint8_t *buf; /* unaligned YV12 buffer */ -} lavc_data_t; - - -int dxr3_encoder_init(dxr3_driver_t *drv) -{ - lavc_data_t* this; - avcodec_init(); - - register_avcodec(&mpeg1video_encoder); - lprintf("lavc init , version %x\n", avcodec_version()); - this = xine_xmalloc(sizeof(lavc_data_t)); - if (!this) return 0; - - this->encoder_data.type = ENC_LAVC; - this->encoder_data.on_update_format = lavc_on_update_format; - this->encoder_data.on_frame_copy = NULL; - this->encoder_data.on_display_frame = lavc_on_display_frame; - this->encoder_data.on_unneeded = lavc_on_unneeded; - this->context = 0; - - drv->enc = &this->encoder_data; - return 1; -} - -/* helper function */ -static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame); - -static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - lavc_data_t *this = (lavc_data_t *)drv->enc; - AVCodec *codec; - unsigned char use_quantizer; - - if (this->context) { - avcodec_close(this->context); - free(this->context); - free(this->picture); - this->context = NULL; - this->picture = NULL; - } - - /* if YUY2 and dimensions changed, we need to re-allocate the - * internal YV12 buffer */ - if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { - int image_size = frame->vo_frame.pitches[0] * frame->oheight; - - this->out[0] = xine_xmalloc_aligned(16, image_size * 3/2, - (void *)&this->buf); - this->out[1] = this->out[0] + image_size; - this->out[2] = this->out[1] + image_size/4; - - /* fill with black (yuv 16,128,128) */ - memset(this->out[0], 16, image_size); - memset(this->out[1], 128, image_size/4); - memset(this->out[2], 128, image_size/4); - lprintf("Using YUY2->YV12 conversion\n"); - } - - /* resolution must be a multiple of two */ - if ((frame->vo_frame.pitches[0] % 2 != 0) || (frame->oheight % 2 != 0)) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: lavc only handles video dimensions which are multiples of 2\n"); - return 0; - } - - /* get mpeg codec handle */ - codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); - if (!codec) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: lavc MPEG1 codec not found\n"); - return 0; - } - lprintf("lavc MPEG1 encoder found.\n"); - - this->width = frame->vo_frame.pitches[0]; - this->height = frame->oheight; - - this->context = avcodec_alloc_context(); - if (!this->context) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't start the ffmpeg library\n"); - return 0; - } - this->picture = avcodec_alloc_frame(); - if (!this->picture) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't allocate ffmpeg frame\n"); - return 0; - } - - /* mpeg1 encoder only support YUV420P */ - this->context->pix_fmt = PIX_FMT_YUVJ420P; - - /* put sample parameters */ - this->context->bit_rate = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_bitrate", 10000, 1000, 20000, - _("libavcodec mpeg output bitrate (kbit/s)"), - _("The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. " - "Higher values will increase quality and CPU usage.\n" - "This setting is only considered, when constant quality mode is disabled."), 10, NULL, NULL); - this->context->bit_rate *= 1000; /* config in kbit/s, libavcodec wants bit/s */ - - use_quantizer = drv->class->xine->config->register_bool(drv->class->xine->config, - "dxr3.encoding.lavc_quantizer", 1, - _("constant quality mode"), - _("When enabled, libavcodec will use a constant quality mode by dynamically " - "compressing the images based on their complexity. When disabled, libavcodec " - "will use constant bitrate mode."), 10, NULL, NULL); - - if (use_quantizer) { - this->context->qmin = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_qmin", 1, 1, 10, - _("minimum compression"), - _("The minimum compression to apply to an image in constant quality mode."), - 10, NULL, NULL); - - this->context->qmax = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_qmax", 2, 1, 20, - _("maximum quantizer"), - _("The maximum compression to apply to an image in constant quality mode."), - 10, NULL, NULL); - } - - lprintf("lavc -> bitrate %d \n", this->context->bit_rate); - - this->context->width = frame->vo_frame.pitches[0]; - this->context->height = frame->oheight; - - this->context->gop_size = 0; /*intra frames only */ - this->context->me_method = ME_ZERO; /*motion estimation type*/ - - this->context->time_base.den = 90000; - if (frame->vo_frame.duration > 90000 / 24) - this->context->time_base.num = 90000 / 24; - else if (frame->vo_frame.duration < 90000 / 60) - this->context->time_base.num = 90000 / 60; - else - this->context->time_base.num = frame->vo_frame.duration; - /* ffmpeg can complain about illegal framerates, but since this seems no - * problem for the DXR3, we just tell ffmpeg to be more lax with */ - this->context->strict_std_compliance = -1; - - /* open avcodec */ - if (avcodec_open(this->context, codec) < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, "dxr3_mpeg_encoder: could not open codec\n"); - return 0; - } - lprintf("dxr3_mpeg_encoder: lavc MPEG1 codec opened.\n"); - - if (!this->ffmpeg_buffer) - this->ffmpeg_buffer = (unsigned char *)malloc(DEFAULT_BUFFER_SIZE); /* why allocate more than needed ?! */ - if (!this->ffmpeg_buffer) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't allocate temp buffer for mpeg data\n"); - return 0; - } - - return 1; -} - -static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - int size; - lavc_data_t* this = (lavc_data_t *)drv->enc; - ssize_t written; - - if (frame->vo_frame.bad_frame) return 1; - /* ignore old frames */ - if ((frame->vo_frame.pitches[0] != this->context->width) || (frame->oheight != this->context->height)) { - frame->vo_frame.free(&frame->vo_frame); - lprintf("LAVC ignoring frame !!!\n"); - return 1; - } - - /* prepare frame for conversion, handles YUY2 -> YV12 conversion when necessary */ - lavc_prepare_frame(this, drv, frame); - - /* do the encoding */ - size = avcodec_encode_video(this->context, this->ffmpeg_buffer, DEFAULT_BUFFER_SIZE, this->picture); - - frame->vo_frame.free(&frame->vo_frame); - - if (size < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: encoding failed\n"); - return 0; - } - - written = write(drv->fd_video, this->ffmpeg_buffer, size); - if (written < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: video device write failed (%s)\n", strerror(errno)); - return 0; - } - if (written != size) - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Could only write %zd of %d mpeg bytes.\n", written, size); - return 1; -} - -static int lavc_on_unneeded(dxr3_driver_t *drv) -{ - lavc_data_t *this = (lavc_data_t *)drv->enc; - lprintf("flushing buffers\n"); - if (this->context) { - avcodec_close(this->context); - free(this->context); - free(this->picture); - this->context = NULL; - this->picture = NULL; - } - return 1; -} - -static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - int i, j, w2; - uint8_t *yuy2; - - if (frame->vo_frame.bad_frame) return 1; - - if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { - /* need YUY2->YV12 conversion */ - if (!(this->out[0] && this->out[1] && this->out[2]) ) { - lprintf("Internal YV12 buffer not created.\n"); - return 0; - } - this->picture->data[0] = this->out[0] + frame->vo_frame.pitches[0] * drv->top_bar; /* y */ - this->picture->data[1] = this->out[1] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* u */ - this->picture->data[2] = this->out[2] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* v */ - yuy2 = frame->vo_frame.base[0]; - w2 = frame->vo_frame.pitches[0] / 2; - for (i = 0; i < frame->vo_frame.height; i += 2) { - for (j = 0; j < w2; j++) { - /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */ - *(this->picture->data[0]++) = *(yuy2++); - *(this->picture->data[1]++) = *(yuy2++); - *(this->picture->data[0]++) = *(yuy2++); - *(this->picture->data[2]++) = *(yuy2++); - } - /* down sampling */ - for (j = 0; j < w2; j++) { - /* skip every second line for U and V */ - *(this->picture->data[0]++) = *(yuy2++); - yuy2++; - *(this->picture->data[0]++) = *(yuy2++); - yuy2++; - } - } - /* reset for encoder */ - this->picture->data[0] = this->out[0]; - this->picture->data[1] = this->out[1]; - this->picture->data[2] = this->out[2]; - } - else { /* YV12 **/ - this->picture->data[0] = frame->real_base[0]; - this->picture->data[1] = frame->real_base[1]; - this->picture->data[2] = frame->real_base[2]; - } - this->picture->linesize[0] = this->context->width; - this->picture->linesize[1] = this->context->width / 2; - this->picture->linesize[2] = this->context->width / 2; - return 1; -} -- cgit v1.2.3 From fce0775e55c1cabe70b5c81f7275b4dc2844b690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 21:15:34 +0200 Subject: Rename xine_decoder.c to xine_a52_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/liba52/xine_decoder.c => src/liba52/xine_a52_decoder.c --- src/liba52/Makefile.am | 8 +- src/liba52/xine_a52_decoder.c | 866 ++++++++++++++++++++++++++++++++++++++++++ src/liba52/xine_decoder.c | 866 ------------------------------------------ 3 files changed, 869 insertions(+), 871 deletions(-) create mode 100644 src/liba52/xine_a52_decoder.c delete mode 100644 src/liba52/xine_decoder.c (limited to 'src') diff --git a/src/liba52/Makefile.am b/src/liba52/Makefile.am index f296a0ef3..6a0aebe62 100644 --- a/src/liba52/Makefile.am +++ b/src/liba52/Makefile.am @@ -1,12 +1,10 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) - if A52 a52_module = xineplug_decode_a52.la endif -lib_LTLIBRARIES = $(a52_module) +xineplug_LTLIBRARIES = $(a52_module) if EXTERNAL_A52DEC internal_sources = @@ -20,7 +18,7 @@ internal_sources = \ endif xineplug_decode_a52_la_SOURCES = \ - xine_decoder.c \ + xine_a52_decoder.c \ $(internal_sources) if EXTERNAL_A52DEC @@ -30,7 +28,7 @@ xineplug_decode_a52_la_LIBADD = $(XINE_LIB) -lm endif xineplug_decode_a52_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_a52_la_LDFLAGS = -avoid-version -module +xineplug_decode_a52_la_LDFLAGS = $(xineplug_ldflags) noinst_HEADERS = \ a52.h \ diff --git a/src/liba52/xine_a52_decoder.c b/src/liba52/xine_a52_decoder.c new file mode 100644 index 000000000..5435e9664 --- /dev/null +++ b/src/liba52/xine_a52_decoder.c @@ -0,0 +1,866 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.81 2007/02/20 00:34:57 dgp85 Exp $ + * + * stuff needed to turn liba52 into a xine decoder plugin + */ + +#ifndef __sun +/* required for swab() */ +#define _XOPEN_SOURCE 500 +#endif +/* avoid compiler warnings */ +#define _BSD_SOURCE 1 + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "a52_decoder" +#define LOG_VERBOSE +/* +#define LOG +#define LOG_PTS +*/ + +#include "xine_internal.h" +#include "audio_out.h" + +#ifdef HAVE_A52DEC_A52_H +# include +#else +# include "a52.h" +#endif + +#ifdef HAVE_A52DEC_A52_INTERNAL_H +# include +#else +# include "a52_internal.h" +#endif + +#include "buffer.h" +#include "xineutils.h" + +#include "crc.c" + +#undef DEBUG_A52 +#ifdef DEBUG_A52 +int a52file; +#endif + +typedef struct { + audio_decoder_class_t decoder_class; + config_values_t *config; + + float a52_level; + int disable_dynrng_compress; + int enable_surround_downmix; + +} a52dec_class_t; + +typedef struct a52dec_decoder_s { + audio_decoder_t audio_decoder; + + a52dec_class_t *class; + xine_stream_t *stream; + int64_t pts; + int64_t pts_list[5]; + int32_t pts_list_position; + + uint8_t frame_buffer[3840]; + uint8_t *frame_ptr; + int sync_state; + int frame_length, frame_todo; + uint16_t syncword; + + a52_state_t *a52_state; + int a52_flags; + int a52_bit_rate; + int a52_sample_rate; + int have_lfe; + + int a52_flags_map[11]; + int ao_flags_map[11]; + + int audio_caps; + int bypass_mode; + int output_sampling_rate; + int output_open; + int output_mode; + +} a52dec_decoder_t; + +struct frmsize_s +{ + uint16_t bit_rate; + uint16_t frm_size[3]; +}; + +static const struct frmsize_s frmsizecod_tbl[64] = +{ + { 32 ,{64 ,69 ,96 } }, + { 32 ,{64 ,70 ,96 } }, + { 40 ,{80 ,87 ,120 } }, + { 40 ,{80 ,88 ,120 } }, + { 48 ,{96 ,104 ,144 } }, + { 48 ,{96 ,105 ,144 } }, + { 56 ,{112 ,121 ,168 } }, + { 56 ,{112 ,122 ,168 } }, + { 64 ,{128 ,139 ,192 } }, + { 64 ,{128 ,140 ,192 } }, + { 80 ,{160 ,174 ,240 } }, + { 80 ,{160 ,175 ,240 } }, + { 96 ,{192 ,208 ,288 } }, + { 96 ,{192 ,209 ,288 } }, + { 112 ,{224 ,243 ,336 } }, + { 112 ,{224 ,244 ,336 } }, + { 128 ,{256 ,278 ,384 } }, + { 128 ,{256 ,279 ,384 } }, + { 160 ,{320 ,348 ,480 } }, + { 160 ,{320 ,349 ,480 } }, + { 192 ,{384 ,417 ,576 } }, + { 192 ,{384 ,418 ,576 } }, + { 224 ,{448 ,487 ,672 } }, + { 224 ,{448 ,488 ,672 } }, + { 256 ,{512 ,557 ,768 } }, + { 256 ,{512 ,558 ,768 } }, + { 320 ,{640 ,696 ,960 } }, + { 320 ,{640 ,697 ,960 } }, + { 384 ,{768 ,835 ,1152 } }, + { 384 ,{768 ,836 ,1152 } }, + { 448 ,{896 ,975 ,1344 } }, + { 448 ,{896 ,976 ,1344 } }, + { 512 ,{1024 ,1114 ,1536 } }, + { 512 ,{1024 ,1115 ,1536 } }, + { 576 ,{1152 ,1253 ,1728 } }, + { 576 ,{1152 ,1254 ,1728 } }, + { 640 ,{1280 ,1393 ,1920 } }, + { 640 ,{1280 ,1394 ,1920 } } +}; + +/* config callbacks */ +static void a52_level_change_cb(void *this_gen, xine_cfg_entry_t *entry); +static void dynrng_compress_change_cb(void *this_gen, xine_cfg_entry_t *entry); +static void surround_downmix_change_cb(void *this_gen, xine_cfg_entry_t *entry); + + +static void a52dec_reset (audio_decoder_t *this_gen) { + + a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; + + this->syncword = 0; + this->sync_state = 0; + this->pts = 0; + this->pts_list[0] = 0; + this->pts_list_position = 0; +} + +static void a52dec_discontinuity (audio_decoder_t *this_gen) { + + a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; + + this->pts = 0; + this->pts_list[0] = 0; + this->pts_list_position = 0; +} + +static inline int16_t blah (int32_t i) { + + if (i > 0x43c07fff) + return 32767; + else if (i < 0x43bf8000) + return -32768; + else + return i - 0x43c00000; +} + +static inline void float_to_int (float * _f, int16_t * s16, int num_channels) { + int i; + int32_t * f = (int32_t *) _f; /* XXX assumes IEEE float format */ + + for (i = 0; i < 256; i++) { + s16[num_channels*i] = blah (f[i]); + } +} + +static inline void mute_channel (int16_t * s16, int num_channels) { + int i; + + for (i = 0; i < 256; i++) { + s16[num_channels*i] = 0; + } +} + +static void a52dec_decode_frame (a52dec_decoder_t *this, int64_t pts, int preview_mode) { + + int output_mode = AO_CAP_MODE_STEREO; + + /* + * do we want to decode this frame in software? + */ +#ifdef LOG_PTS + printf("a52dec:decode_frame:pts=%lld\n",pts); +#endif + if (!this->bypass_mode) { + + int a52_output_flags, i; + sample_t level = this->class->a52_level; + audio_buffer_t *buf; + int16_t *int_samples; + sample_t *samples = a52_samples(this->a52_state); + + /* + * oki, decode this frame in software + */ + + /* determine output mode */ + + a52_output_flags = this->a52_flags_map[this->a52_flags & A52_CHANNEL_MASK]; + + if (a52_frame (this->a52_state, + this->frame_buffer, + &a52_output_flags, + &level, 384)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: a52_frame error\n"); + return; + } + + if (this->class->disable_dynrng_compress) + a52_dynrng (this->a52_state, NULL, NULL); + + this->have_lfe = a52_output_flags & A52_LFE; + if (this->have_lfe) + if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { + output_mode = AO_CAP_MODE_5_1CHANNEL; + } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { + output_mode = AO_CAP_MODE_4_1CHANNEL; + } else { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: WHAT DO I DO!!!\n"); + output_mode = this->ao_flags_map[a52_output_flags]; + } + else + output_mode = this->ao_flags_map[a52_output_flags]; + /* + * (re-)open output device + */ + + if (!this->output_open + || (this->a52_sample_rate != this->output_sampling_rate) + || (output_mode != this->output_mode)) { + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + + this->output_open = this->stream->audio_out->open (this->stream->audio_out, + this->stream, 16, + this->a52_sample_rate, + output_mode) ; + this->output_sampling_rate = this->a52_sample_rate; + this->output_mode = output_mode; + } + + + if (!this->output_open || preview_mode) + return; + + + /* + * decode a52 and convert/interleave samples + */ + + buf = this->stream->audio_out->get_buffer (this->stream->audio_out); + int_samples = buf->mem; + buf->num_frames = 256*6; + + for (i = 0; i < 6; i++) { + if (a52_block (this->a52_state)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: a52_block error on audio channel %d\n", i); +#if 0 + for(n=0;n<2000;n++) { + printf("%02x ",this->frame_buffer[n]); + if ((n % 32) == 0) printf("\n"); + } + printf("\n"); +#endif + buf->num_frames = 0; + break; + } + + switch (output_mode) { + case AO_CAP_MODE_MONO: + float_to_int (&samples[0], int_samples+(i*256), 1); + break; + case AO_CAP_MODE_STEREO: + float_to_int (&samples[0*256], int_samples+(i*256*2), 2); + float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); + break; + case AO_CAP_MODE_4CHANNEL: + float_to_int (&samples[0*256], int_samples+(i*256*4), 4); /* L */ + float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /* R */ + float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */ + float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */ + break; + case AO_CAP_MODE_4_1CHANNEL: + float_to_int (&samples[0*256], int_samples+(i*256*6)+5, 6); /* LFE */ + float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ + float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ + float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ + float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ + mute_channel ( int_samples+(i*256*6)+4, 6); /* C */ + break; + case AO_CAP_MODE_5CHANNEL: + float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /* L */ + float_to_int (&samples[1*256], int_samples+(i*256*6)+4, 6); /* C */ + float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ + float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ + float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ + mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */ + break; + case AO_CAP_MODE_5_1CHANNEL: + float_to_int (&samples[0*256], int_samples+(i*256*6)+5, 6); /* lfe */ + float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ + float_to_int (&samples[2*256], int_samples+(i*256*6)+4, 6); /* C */ + float_to_int (&samples[3*256], int_samples+(i*256*6)+1, 6); /* R */ + float_to_int (&samples[4*256], int_samples+(i*256*6)+2, 6); /* RL */ + float_to_int (&samples[5*256], int_samples+(i*256*6)+3, 6); /* RR */ + break; + default: + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: help - unsupported mode %08x\n", output_mode); + } + } + + lprintf ("%d frames output\n", buf->num_frames); + + /* output decoded samples */ + + buf->vpts = pts; + + this->stream->audio_out->put_buffer (this->stream->audio_out, buf, this->stream); + + } else { + + /* + * loop through a52 data + */ + + if (!this->output_open) { + + int sample_rate, bit_rate, flags; + + a52_syncinfo (this->frame_buffer, &flags, &sample_rate, &bit_rate); + + this->output_open = this->stream->audio_out->open (this->stream->audio_out, + this->stream, 16, + sample_rate, + AO_CAP_MODE_A52) ; + this->output_mode = AO_CAP_MODE_A52; + } + + if (this->output_open && !preview_mode) { + /* SPDIF Passthrough + * Build SPDIF Header and encaps the A52 audio data in it. + */ + uint32_t syncword, crc1, fscod,frmsizecod,bsid,bsmod,frame_size; + uint8_t *data_out,*data_in; + audio_buffer_t *buf = this->stream->audio_out->get_buffer (this->stream->audio_out); + data_in=(uint8_t *) this->frame_buffer; + data_out=(uint8_t *) buf->mem; + syncword = data_in[0] | (data_in[1] << 8); + crc1 = data_in[2] | (data_in[3] << 8); + fscod = (data_in[4] >> 6) & 0x3; + frmsizecod = data_in[4] & 0x3f; + bsid = (data_in[5] >> 3) & 0x1f; + bsmod = data_in[5] & 0x7; /* bsmod, stream = 0 */ + frame_size = frmsizecod_tbl[frmsizecod].frm_size[fscod] ; + + data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */ + data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */ + data_out[4] = 0x01; /* AC3 data */ + data_out[5] = bsmod; /* bsmod, stream = 0 */ + data_out[6] = (frame_size << 4) & 0xff; /* frame_size * 16 */ + data_out[7] = ((frame_size ) >> 4) & 0xff; + swab(data_in, &data_out[8], frame_size * 2 ); + + buf->num_frames = 1536; + buf->vpts = pts; + + this->stream->audio_out->put_buffer (this->stream->audio_out, buf, this->stream); + + } + } +} + +static void a52dec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; + uint8_t *current = buf->content; + uint8_t *sync_start=current + 1; + uint8_t *end = buf->content + buf->size; + uint8_t byte; + int32_t n; + uint16_t crc16; + uint16_t crc16_result; + + lprintf ("decode data %d bytes of type %08x, pts=%"PRId64"\n", + buf->size, buf->type, buf->pts); + lprintf ("decode data decoder_info=%d, %d\n",buf->decoder_info[1],buf->decoder_info[2]); + + if (buf->decoder_flags & BUF_FLAG_HEADER) + return; + + /* swap byte pairs if this is RealAudio DNET data */ + if (buf->type == BUF_AUDIO_DNET) { + + lprintf ("byte-swapping dnet\n"); + + while (current != end) { + byte = *current++; + *(current - 1) = *current; + *current++ = byte; + } + + /* reset */ + current = buf->content; + end = buf->content + buf->size; + } + + /* A52 packs come from the DVD in blocks of about 2048 bytes. + * Only 1 PTS values can be assigned to each block. + * An A52 frame is about 1700 bytes long. + * So, a single A52 packs can contain 2 A52 frames (or the beginning of an A52 frame at least). + * If we have a PTS value, which A52 frame does it apply to? The A52 pack tells us that. + * So, the info about which A52 frame the PTS applies to is contained in decoder_info sent from the demuxer. + * + * The PTS value from the A52 pack (DVD sector) can only be applied at the start of an A52 frame. + * We call the start of an A52 frame a frame header. + * So, if a A52 pack has 2 "Number of frame headers" is means that the A52 pack contains 2 A52 frame headers. + * The "First access unit" then tells us which A52 frame the PTS value applies to. + * + * Take the following example: - + * PACK1: PTS = 10. Contains the entire A52 frame1, followed by the beginning of the frame2. PTS applies to frame1. + * PACK2: PTS = 1000, Contains the rest of frame2, and the whole of frame3. and the start of frame4. PTS applies to frame4. + * PACK3: PTS = 0 (none), Contains the rest of frame4. + * + * Output should be: - + * frame1, PTS=10 + * frame2, PTS=0 + * frame3, PTS=0 + * frame4, PTS=1000 + * + * So, we have to keep track of PTS values from previous A52 packs here, otherwise they get put on the wrong frame. + */ + + + /* FIXME: the code here does not match the explanation above */ + if (buf->pts) { + int32_t info; + info = buf->decoder_info[1]; + this->pts = buf->pts; + this->pts_list[this->pts_list_position]=buf->pts; + this->pts_list_position++; + if( this->pts_list_position > 3 ) + this->pts_list_position = 3; + if (info == 2) { + this->pts_list[this->pts_list_position]=0; + this->pts_list_position++; + if( this->pts_list_position > 3 ) + this->pts_list_position = 3; + } + } +#if 0 + for(n=0;n < buf->size;n++) { + if ((n % 32) == 0) printf("\n"); + printf("%x ", current[n]); + } + printf("\n"); +#endif + + lprintf ("processing...state %d\n", this->sync_state); + + while (current < end) { + switch (this->sync_state) { + case 0: /* Looking for sync header */ + this->syncword = (this->syncword << 8) | *current++; + if (this->syncword == 0x0b77) { + + this->frame_buffer[0] = 0x0b; + this->frame_buffer[1] = 0x77; + + this->sync_state = 1; + this->frame_ptr = this->frame_buffer+2; + } + break; + + case 1: /* Looking for enough bytes for sync_info. */ + sync_start = current - 1; + *this->frame_ptr++ = *current++; + if ((this->frame_ptr - this->frame_buffer) > 16) { + int a52_flags_old = this->a52_flags; + int a52_sample_rate_old = this->a52_sample_rate; + int a52_bit_rate_old = this->a52_bit_rate; + + this->frame_length = a52_syncinfo (this->frame_buffer, + &this->a52_flags, + &this->a52_sample_rate, + &this->a52_bit_rate); + + if (this->frame_length < 80) { /* Invalid a52 frame_length */ + this->syncword = 0; + current = sync_start; + this->sync_state = 0; + break; + } + + lprintf("Frame length = %d\n",this->frame_length); + + this->frame_todo = this->frame_length - 17; + this->sync_state = 2; + if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) || + a52_flags_old != this->a52_flags || + a52_sample_rate_old != this->a52_sample_rate || + a52_bit_rate_old != this->a52_bit_rate) { + + switch (this->a52_flags & A52_CHANNEL_MASK) { + case A52_3F2R: + if (this->a52_flags & A52_LFE) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 5.1"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 5.0"); + break; + case A52_3F1R: + case A52_2F2R: + if (this->a52_flags & A52_LFE) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 4.1"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 4.0"); + break; + case A52_2F1R: + case A52_3F: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 3.0"); + break; + case A52_STEREO: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 2.0 (stereo)"); + break; + case A52_DOLBY: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 2.0 (dolby)"); + break; + case A52_MONO: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 1.0"); + break; + default: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52"); + break; + } + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->a52_bit_rate); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->a52_sample_rate); + } + } + break; + + case 2: /* Filling frame_buffer with sync_info bytes */ + *this->frame_ptr++ = *current++; + this->frame_todo--; + if (this->frame_todo < 1) { + this->sync_state = 3; + } else break; + + case 3: /* Ready for decode */ + crc16 = (uint16_t) ((this->frame_buffer[2] << 8) | this->frame_buffer[3]) ; + crc16_result = crc16_block(&this->frame_buffer[2], this->frame_length - 2) ; /* frame_length */ + if (crc16_result != 0) { /* CRC16 failed */ + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52:a52 frame failed crc16 checksum.\n"); + current = sync_start; + this->pts = 0; + this->syncword = 0; + this->sync_state = 0; + break; + } +#if 0 + a52dec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW); +#else + a52dec_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW); +#endif + for(n=0;n<4;n++) { + this->pts_list[n] = this->pts_list[n+1]; + } + this->pts_list_position--; + if( this->pts_list_position < 0 ) + this->pts_list_position = 0; +#if 0 + printf("liba52: pts_list = %lld, %lld, %lld\n", + this->pts_list[0], + this->pts_list[1], + this->pts_list[2]); +#endif + case 4: /* Clear up ready for next frame */ + this->pts = 0; + this->syncword = 0; + this->sync_state = 0; + break; + default: /* No come here */ + break; + } + } + +#ifdef DEBUG_A52 + write (a52file, this->frame_buffer, this->frame_length); +#endif +} + +static void a52dec_dispose (audio_decoder_t *this_gen) { + + a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + this->output_open = 0; + + a52_free(this->a52_state); + this->a52_state = NULL; + +#ifdef DEBUG_A52 + close (a52file); +#endif + free (this_gen); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + a52dec_decoder_t *this ; + + lprintf ("open_plugin called\n"); + + this = (a52dec_decoder_t *) xine_xmalloc (sizeof (a52dec_decoder_t)); + + this->audio_decoder.decode_data = a52dec_decode_data; + this->audio_decoder.reset = a52dec_reset; + this->audio_decoder.discontinuity = a52dec_discontinuity; + this->audio_decoder.dispose = a52dec_dispose; + this->stream = stream; + this->class = (a52dec_class_t *) class_gen; + + /* int i; */ + + this->audio_caps = stream->audio_out->get_capabilities(stream->audio_out); + this->syncword = 0; + this->sync_state = 0; + this->output_open = 0; + this->pts = 0; + this->pts_list[0] = 0; + this->pts_list_position = 0; + + if( !this->a52_state ) + this->a52_state = a52_init (xine_mm_accel()); + + /* + * find out if this driver supports a52 output + * or, if not, how many channels we've got + */ + + if (this->audio_caps & AO_CAP_MODE_A52) + this->bypass_mode = 1; + else { + this->bypass_mode = 0; + + this->a52_flags_map[A52_MONO] = A52_MONO; + this->a52_flags_map[A52_STEREO] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + this->a52_flags_map[A52_3F] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + this->a52_flags_map[A52_2F1R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + this->a52_flags_map[A52_3F1R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + this->a52_flags_map[A52_2F2R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + this->a52_flags_map[A52_3F2R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + this->a52_flags_map[A52_DOLBY] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); + + this->ao_flags_map[A52_MONO] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_STEREO] = AO_CAP_MODE_STEREO; + this->ao_flags_map[A52_3F] = AO_CAP_MODE_STEREO; + this->ao_flags_map[A52_2F1R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[A52_3F1R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[A52_DOLBY] = AO_CAP_MODE_STEREO; + + /* find best mode */ + if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { + + this->a52_flags_map[A52_2F2R] = A52_2F2R; + this->a52_flags_map[A52_3F2R] = A52_3F2R | A52_LFE; + this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_5CHANNEL; + + } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) { + + this->a52_flags_map[A52_2F2R] = A52_2F2R; + this->a52_flags_map[A52_3F2R] = A52_3F2R; + this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_5CHANNEL; + + } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { + + this->a52_flags_map[A52_2F2R] = A52_2F2R; + this->a52_flags_map[A52_3F2R] = A52_2F2R | A52_LFE; + this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_4CHANNEL; + + } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) { + + this->a52_flags_map[A52_2F2R] = A52_2F2R; + this->a52_flags_map[A52_3F2R] = A52_2F2R; + + this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_4CHANNEL; + + /* else if (this->audio_caps & AO_CAP_MODE_STEREO) + defaults are ok */ + } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n")); + + this->a52_flags_map[A52_MONO] = A52_MONO; + this->a52_flags_map[A52_STEREO] = A52_MONO; + this->a52_flags_map[A52_3F] = A52_MONO; + this->a52_flags_map[A52_2F1R] = A52_MONO; + this->a52_flags_map[A52_3F1R] = A52_MONO; + this->a52_flags_map[A52_2F2R] = A52_MONO; + this->a52_flags_map[A52_3F2R] = A52_MONO; + this->a52_flags_map[A52_DOLBY] = A52_MONO; + + this->ao_flags_map[A52_MONO] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_STEREO] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_3F] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_2F1R] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_3F1R] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_MONO; + this->ao_flags_map[A52_DOLBY] = AO_CAP_MODE_MONO; + } + } + + /* + for (i = 0; i<8; i++) + this->a52_flags_map[i] |= A52_ADJUST_LEVEL; + */ +#ifdef DEBUG_A52 + a52file = open ("test.a52", O_CREAT | O_WRONLY | O_TRUNC, 0644); +#endif + return &this->audio_decoder; +} + +static char *get_identifier (audio_decoder_class_t *this) { + lprintf ("get_identifier called\n"); + return "a/52dec"; +} + +static char *get_description (audio_decoder_class_t *this) { + lprintf ("get_description called\n"); + return "liba52 based a52 audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + lprintf ("dispose_class called\n"); + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + a52dec_class_t *this; + config_values_t *cfg; + + this = (a52dec_class_t *) xine_xmalloc (sizeof (a52dec_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + cfg = this->config = xine->config; + + this->a52_level = (float) cfg->register_range (cfg, "audio.a52.level", 100, + 0, 200, + _("A/52 volume"), + _("With A/52 audio, you can modify the volume " + "at the decoder level. This has the advantage " + "of the audio being already decoded for the " + "specified volume, so later operations like " + "channel downmixing will work on an audio stream " + "of the given volume."), + 10, a52_level_change_cb, this) / 100.0; + this->disable_dynrng_compress = !cfg->register_bool (cfg, "audio.a52.dynamic_range", 0, + _("use A/52 dynamic range compression"), + _("Dynamic range compression limits the dynamic " + "range of the audio. This means making the loud " + "sounds softer, and the soft sounds louder, so you can " + "more easily listen to the audio in a noisy " + "environment without disturbing anyone."), + 0, dynrng_compress_change_cb, this); + this->enable_surround_downmix = cfg->register_bool (cfg, "audio.a52.surround_downmix", 0, + _("downmix audio to 2 channel surround stereo"), + _("When you want to listen to multichannel surround " + "sound, but you have only two speakers or a " + "surround decoder or amplifier which does some " + "sort of matrix surround decoding like prologic, " + "you should enable this option so that the " + "additional channels are mixed into the stereo " + "signal."), + 0, surround_downmix_change_cb, this); + lprintf ("init_plugin called\n"); + return this; +} + +static void a52_level_change_cb(void *this_gen, xine_cfg_entry_t *entry) +{ + ((a52dec_class_t *)this_gen)->a52_level = entry->num_value / 100.0; +} + +static void dynrng_compress_change_cb(void *this_gen, xine_cfg_entry_t *entry) +{ + ((a52dec_class_t *)this_gen)->disable_dynrng_compress = !entry->num_value; +} + +static void surround_downmix_change_cb(void *this_gen, xine_cfg_entry_t *entry) +{ + ((a52dec_class_t *)this_gen)->enable_surround_downmix = entry->num_value; +} + + +static uint32_t audio_types[] = { + BUF_AUDIO_A52, + BUF_AUDIO_DNET, + 0 + }; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER | PLUGIN_MUST_PRELOAD, 15, "a/52", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/liba52/xine_decoder.c b/src/liba52/xine_decoder.c deleted file mode 100644 index 5435e9664..000000000 --- a/src/liba52/xine_decoder.c +++ /dev/null @@ -1,866 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.81 2007/02/20 00:34:57 dgp85 Exp $ - * - * stuff needed to turn liba52 into a xine decoder plugin - */ - -#ifndef __sun -/* required for swab() */ -#define _XOPEN_SOURCE 500 -#endif -/* avoid compiler warnings */ -#define _BSD_SOURCE 1 - -#include - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "a52_decoder" -#define LOG_VERBOSE -/* -#define LOG -#define LOG_PTS -*/ - -#include "xine_internal.h" -#include "audio_out.h" - -#ifdef HAVE_A52DEC_A52_H -# include -#else -# include "a52.h" -#endif - -#ifdef HAVE_A52DEC_A52_INTERNAL_H -# include -#else -# include "a52_internal.h" -#endif - -#include "buffer.h" -#include "xineutils.h" - -#include "crc.c" - -#undef DEBUG_A52 -#ifdef DEBUG_A52 -int a52file; -#endif - -typedef struct { - audio_decoder_class_t decoder_class; - config_values_t *config; - - float a52_level; - int disable_dynrng_compress; - int enable_surround_downmix; - -} a52dec_class_t; - -typedef struct a52dec_decoder_s { - audio_decoder_t audio_decoder; - - a52dec_class_t *class; - xine_stream_t *stream; - int64_t pts; - int64_t pts_list[5]; - int32_t pts_list_position; - - uint8_t frame_buffer[3840]; - uint8_t *frame_ptr; - int sync_state; - int frame_length, frame_todo; - uint16_t syncword; - - a52_state_t *a52_state; - int a52_flags; - int a52_bit_rate; - int a52_sample_rate; - int have_lfe; - - int a52_flags_map[11]; - int ao_flags_map[11]; - - int audio_caps; - int bypass_mode; - int output_sampling_rate; - int output_open; - int output_mode; - -} a52dec_decoder_t; - -struct frmsize_s -{ - uint16_t bit_rate; - uint16_t frm_size[3]; -}; - -static const struct frmsize_s frmsizecod_tbl[64] = -{ - { 32 ,{64 ,69 ,96 } }, - { 32 ,{64 ,70 ,96 } }, - { 40 ,{80 ,87 ,120 } }, - { 40 ,{80 ,88 ,120 } }, - { 48 ,{96 ,104 ,144 } }, - { 48 ,{96 ,105 ,144 } }, - { 56 ,{112 ,121 ,168 } }, - { 56 ,{112 ,122 ,168 } }, - { 64 ,{128 ,139 ,192 } }, - { 64 ,{128 ,140 ,192 } }, - { 80 ,{160 ,174 ,240 } }, - { 80 ,{160 ,175 ,240 } }, - { 96 ,{192 ,208 ,288 } }, - { 96 ,{192 ,209 ,288 } }, - { 112 ,{224 ,243 ,336 } }, - { 112 ,{224 ,244 ,336 } }, - { 128 ,{256 ,278 ,384 } }, - { 128 ,{256 ,279 ,384 } }, - { 160 ,{320 ,348 ,480 } }, - { 160 ,{320 ,349 ,480 } }, - { 192 ,{384 ,417 ,576 } }, - { 192 ,{384 ,418 ,576 } }, - { 224 ,{448 ,487 ,672 } }, - { 224 ,{448 ,488 ,672 } }, - { 256 ,{512 ,557 ,768 } }, - { 256 ,{512 ,558 ,768 } }, - { 320 ,{640 ,696 ,960 } }, - { 320 ,{640 ,697 ,960 } }, - { 384 ,{768 ,835 ,1152 } }, - { 384 ,{768 ,836 ,1152 } }, - { 448 ,{896 ,975 ,1344 } }, - { 448 ,{896 ,976 ,1344 } }, - { 512 ,{1024 ,1114 ,1536 } }, - { 512 ,{1024 ,1115 ,1536 } }, - { 576 ,{1152 ,1253 ,1728 } }, - { 576 ,{1152 ,1254 ,1728 } }, - { 640 ,{1280 ,1393 ,1920 } }, - { 640 ,{1280 ,1394 ,1920 } } -}; - -/* config callbacks */ -static void a52_level_change_cb(void *this_gen, xine_cfg_entry_t *entry); -static void dynrng_compress_change_cb(void *this_gen, xine_cfg_entry_t *entry); -static void surround_downmix_change_cb(void *this_gen, xine_cfg_entry_t *entry); - - -static void a52dec_reset (audio_decoder_t *this_gen) { - - a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; - - this->syncword = 0; - this->sync_state = 0; - this->pts = 0; - this->pts_list[0] = 0; - this->pts_list_position = 0; -} - -static void a52dec_discontinuity (audio_decoder_t *this_gen) { - - a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; - - this->pts = 0; - this->pts_list[0] = 0; - this->pts_list_position = 0; -} - -static inline int16_t blah (int32_t i) { - - if (i > 0x43c07fff) - return 32767; - else if (i < 0x43bf8000) - return -32768; - else - return i - 0x43c00000; -} - -static inline void float_to_int (float * _f, int16_t * s16, int num_channels) { - int i; - int32_t * f = (int32_t *) _f; /* XXX assumes IEEE float format */ - - for (i = 0; i < 256; i++) { - s16[num_channels*i] = blah (f[i]); - } -} - -static inline void mute_channel (int16_t * s16, int num_channels) { - int i; - - for (i = 0; i < 256; i++) { - s16[num_channels*i] = 0; - } -} - -static void a52dec_decode_frame (a52dec_decoder_t *this, int64_t pts, int preview_mode) { - - int output_mode = AO_CAP_MODE_STEREO; - - /* - * do we want to decode this frame in software? - */ -#ifdef LOG_PTS - printf("a52dec:decode_frame:pts=%lld\n",pts); -#endif - if (!this->bypass_mode) { - - int a52_output_flags, i; - sample_t level = this->class->a52_level; - audio_buffer_t *buf; - int16_t *int_samples; - sample_t *samples = a52_samples(this->a52_state); - - /* - * oki, decode this frame in software - */ - - /* determine output mode */ - - a52_output_flags = this->a52_flags_map[this->a52_flags & A52_CHANNEL_MASK]; - - if (a52_frame (this->a52_state, - this->frame_buffer, - &a52_output_flags, - &level, 384)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: a52_frame error\n"); - return; - } - - if (this->class->disable_dynrng_compress) - a52_dynrng (this->a52_state, NULL, NULL); - - this->have_lfe = a52_output_flags & A52_LFE; - if (this->have_lfe) - if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { - output_mode = AO_CAP_MODE_5_1CHANNEL; - } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { - output_mode = AO_CAP_MODE_4_1CHANNEL; - } else { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: WHAT DO I DO!!!\n"); - output_mode = this->ao_flags_map[a52_output_flags]; - } - else - output_mode = this->ao_flags_map[a52_output_flags]; - /* - * (re-)open output device - */ - - if (!this->output_open - || (this->a52_sample_rate != this->output_sampling_rate) - || (output_mode != this->output_mode)) { - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - - this->output_open = this->stream->audio_out->open (this->stream->audio_out, - this->stream, 16, - this->a52_sample_rate, - output_mode) ; - this->output_sampling_rate = this->a52_sample_rate; - this->output_mode = output_mode; - } - - - if (!this->output_open || preview_mode) - return; - - - /* - * decode a52 and convert/interleave samples - */ - - buf = this->stream->audio_out->get_buffer (this->stream->audio_out); - int_samples = buf->mem; - buf->num_frames = 256*6; - - for (i = 0; i < 6; i++) { - if (a52_block (this->a52_state)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: a52_block error on audio channel %d\n", i); -#if 0 - for(n=0;n<2000;n++) { - printf("%02x ",this->frame_buffer[n]); - if ((n % 32) == 0) printf("\n"); - } - printf("\n"); -#endif - buf->num_frames = 0; - break; - } - - switch (output_mode) { - case AO_CAP_MODE_MONO: - float_to_int (&samples[0], int_samples+(i*256), 1); - break; - case AO_CAP_MODE_STEREO: - float_to_int (&samples[0*256], int_samples+(i*256*2), 2); - float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); - break; - case AO_CAP_MODE_4CHANNEL: - float_to_int (&samples[0*256], int_samples+(i*256*4), 4); /* L */ - float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /* R */ - float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */ - float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */ - break; - case AO_CAP_MODE_4_1CHANNEL: - float_to_int (&samples[0*256], int_samples+(i*256*6)+5, 6); /* LFE */ - float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ - float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ - float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ - float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ - mute_channel ( int_samples+(i*256*6)+4, 6); /* C */ - break; - case AO_CAP_MODE_5CHANNEL: - float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /* L */ - float_to_int (&samples[1*256], int_samples+(i*256*6)+4, 6); /* C */ - float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ - float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ - float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ - mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */ - break; - case AO_CAP_MODE_5_1CHANNEL: - float_to_int (&samples[0*256], int_samples+(i*256*6)+5, 6); /* lfe */ - float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ - float_to_int (&samples[2*256], int_samples+(i*256*6)+4, 6); /* C */ - float_to_int (&samples[3*256], int_samples+(i*256*6)+1, 6); /* R */ - float_to_int (&samples[4*256], int_samples+(i*256*6)+2, 6); /* RL */ - float_to_int (&samples[5*256], int_samples+(i*256*6)+3, 6); /* RR */ - break; - default: - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52: help - unsupported mode %08x\n", output_mode); - } - } - - lprintf ("%d frames output\n", buf->num_frames); - - /* output decoded samples */ - - buf->vpts = pts; - - this->stream->audio_out->put_buffer (this->stream->audio_out, buf, this->stream); - - } else { - - /* - * loop through a52 data - */ - - if (!this->output_open) { - - int sample_rate, bit_rate, flags; - - a52_syncinfo (this->frame_buffer, &flags, &sample_rate, &bit_rate); - - this->output_open = this->stream->audio_out->open (this->stream->audio_out, - this->stream, 16, - sample_rate, - AO_CAP_MODE_A52) ; - this->output_mode = AO_CAP_MODE_A52; - } - - if (this->output_open && !preview_mode) { - /* SPDIF Passthrough - * Build SPDIF Header and encaps the A52 audio data in it. - */ - uint32_t syncword, crc1, fscod,frmsizecod,bsid,bsmod,frame_size; - uint8_t *data_out,*data_in; - audio_buffer_t *buf = this->stream->audio_out->get_buffer (this->stream->audio_out); - data_in=(uint8_t *) this->frame_buffer; - data_out=(uint8_t *) buf->mem; - syncword = data_in[0] | (data_in[1] << 8); - crc1 = data_in[2] | (data_in[3] << 8); - fscod = (data_in[4] >> 6) & 0x3; - frmsizecod = data_in[4] & 0x3f; - bsid = (data_in[5] >> 3) & 0x1f; - bsmod = data_in[5] & 0x7; /* bsmod, stream = 0 */ - frame_size = frmsizecod_tbl[frmsizecod].frm_size[fscod] ; - - data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */ - data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */ - data_out[4] = 0x01; /* AC3 data */ - data_out[5] = bsmod; /* bsmod, stream = 0 */ - data_out[6] = (frame_size << 4) & 0xff; /* frame_size * 16 */ - data_out[7] = ((frame_size ) >> 4) & 0xff; - swab(data_in, &data_out[8], frame_size * 2 ); - - buf->num_frames = 1536; - buf->vpts = pts; - - this->stream->audio_out->put_buffer (this->stream->audio_out, buf, this->stream); - - } - } -} - -static void a52dec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; - uint8_t *current = buf->content; - uint8_t *sync_start=current + 1; - uint8_t *end = buf->content + buf->size; - uint8_t byte; - int32_t n; - uint16_t crc16; - uint16_t crc16_result; - - lprintf ("decode data %d bytes of type %08x, pts=%"PRId64"\n", - buf->size, buf->type, buf->pts); - lprintf ("decode data decoder_info=%d, %d\n",buf->decoder_info[1],buf->decoder_info[2]); - - if (buf->decoder_flags & BUF_FLAG_HEADER) - return; - - /* swap byte pairs if this is RealAudio DNET data */ - if (buf->type == BUF_AUDIO_DNET) { - - lprintf ("byte-swapping dnet\n"); - - while (current != end) { - byte = *current++; - *(current - 1) = *current; - *current++ = byte; - } - - /* reset */ - current = buf->content; - end = buf->content + buf->size; - } - - /* A52 packs come from the DVD in blocks of about 2048 bytes. - * Only 1 PTS values can be assigned to each block. - * An A52 frame is about 1700 bytes long. - * So, a single A52 packs can contain 2 A52 frames (or the beginning of an A52 frame at least). - * If we have a PTS value, which A52 frame does it apply to? The A52 pack tells us that. - * So, the info about which A52 frame the PTS applies to is contained in decoder_info sent from the demuxer. - * - * The PTS value from the A52 pack (DVD sector) can only be applied at the start of an A52 frame. - * We call the start of an A52 frame a frame header. - * So, if a A52 pack has 2 "Number of frame headers" is means that the A52 pack contains 2 A52 frame headers. - * The "First access unit" then tells us which A52 frame the PTS value applies to. - * - * Take the following example: - - * PACK1: PTS = 10. Contains the entire A52 frame1, followed by the beginning of the frame2. PTS applies to frame1. - * PACK2: PTS = 1000, Contains the rest of frame2, and the whole of frame3. and the start of frame4. PTS applies to frame4. - * PACK3: PTS = 0 (none), Contains the rest of frame4. - * - * Output should be: - - * frame1, PTS=10 - * frame2, PTS=0 - * frame3, PTS=0 - * frame4, PTS=1000 - * - * So, we have to keep track of PTS values from previous A52 packs here, otherwise they get put on the wrong frame. - */ - - - /* FIXME: the code here does not match the explanation above */ - if (buf->pts) { - int32_t info; - info = buf->decoder_info[1]; - this->pts = buf->pts; - this->pts_list[this->pts_list_position]=buf->pts; - this->pts_list_position++; - if( this->pts_list_position > 3 ) - this->pts_list_position = 3; - if (info == 2) { - this->pts_list[this->pts_list_position]=0; - this->pts_list_position++; - if( this->pts_list_position > 3 ) - this->pts_list_position = 3; - } - } -#if 0 - for(n=0;n < buf->size;n++) { - if ((n % 32) == 0) printf("\n"); - printf("%x ", current[n]); - } - printf("\n"); -#endif - - lprintf ("processing...state %d\n", this->sync_state); - - while (current < end) { - switch (this->sync_state) { - case 0: /* Looking for sync header */ - this->syncword = (this->syncword << 8) | *current++; - if (this->syncword == 0x0b77) { - - this->frame_buffer[0] = 0x0b; - this->frame_buffer[1] = 0x77; - - this->sync_state = 1; - this->frame_ptr = this->frame_buffer+2; - } - break; - - case 1: /* Looking for enough bytes for sync_info. */ - sync_start = current - 1; - *this->frame_ptr++ = *current++; - if ((this->frame_ptr - this->frame_buffer) > 16) { - int a52_flags_old = this->a52_flags; - int a52_sample_rate_old = this->a52_sample_rate; - int a52_bit_rate_old = this->a52_bit_rate; - - this->frame_length = a52_syncinfo (this->frame_buffer, - &this->a52_flags, - &this->a52_sample_rate, - &this->a52_bit_rate); - - if (this->frame_length < 80) { /* Invalid a52 frame_length */ - this->syncword = 0; - current = sync_start; - this->sync_state = 0; - break; - } - - lprintf("Frame length = %d\n",this->frame_length); - - this->frame_todo = this->frame_length - 17; - this->sync_state = 2; - if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) || - a52_flags_old != this->a52_flags || - a52_sample_rate_old != this->a52_sample_rate || - a52_bit_rate_old != this->a52_bit_rate) { - - switch (this->a52_flags & A52_CHANNEL_MASK) { - case A52_3F2R: - if (this->a52_flags & A52_LFE) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 5.1"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 5.0"); - break; - case A52_3F1R: - case A52_2F2R: - if (this->a52_flags & A52_LFE) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 4.1"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 4.0"); - break; - case A52_2F1R: - case A52_3F: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 3.0"); - break; - case A52_STEREO: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 2.0 (stereo)"); - break; - case A52_DOLBY: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 2.0 (dolby)"); - break; - case A52_MONO: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52 1.0"); - break; - default: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "A/52"); - break; - } - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->a52_bit_rate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->a52_sample_rate); - } - } - break; - - case 2: /* Filling frame_buffer with sync_info bytes */ - *this->frame_ptr++ = *current++; - this->frame_todo--; - if (this->frame_todo < 1) { - this->sync_state = 3; - } else break; - - case 3: /* Ready for decode */ - crc16 = (uint16_t) ((this->frame_buffer[2] << 8) | this->frame_buffer[3]) ; - crc16_result = crc16_block(&this->frame_buffer[2], this->frame_length - 2) ; /* frame_length */ - if (crc16_result != 0) { /* CRC16 failed */ - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "liba52:a52 frame failed crc16 checksum.\n"); - current = sync_start; - this->pts = 0; - this->syncword = 0; - this->sync_state = 0; - break; - } -#if 0 - a52dec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW); -#else - a52dec_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW); -#endif - for(n=0;n<4;n++) { - this->pts_list[n] = this->pts_list[n+1]; - } - this->pts_list_position--; - if( this->pts_list_position < 0 ) - this->pts_list_position = 0; -#if 0 - printf("liba52: pts_list = %lld, %lld, %lld\n", - this->pts_list[0], - this->pts_list[1], - this->pts_list[2]); -#endif - case 4: /* Clear up ready for next frame */ - this->pts = 0; - this->syncword = 0; - this->sync_state = 0; - break; - default: /* No come here */ - break; - } - } - -#ifdef DEBUG_A52 - write (a52file, this->frame_buffer, this->frame_length); -#endif -} - -static void a52dec_dispose (audio_decoder_t *this_gen) { - - a52dec_decoder_t *this = (a52dec_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - this->output_open = 0; - - a52_free(this->a52_state); - this->a52_state = NULL; - -#ifdef DEBUG_A52 - close (a52file); -#endif - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - a52dec_decoder_t *this ; - - lprintf ("open_plugin called\n"); - - this = (a52dec_decoder_t *) xine_xmalloc (sizeof (a52dec_decoder_t)); - - this->audio_decoder.decode_data = a52dec_decode_data; - this->audio_decoder.reset = a52dec_reset; - this->audio_decoder.discontinuity = a52dec_discontinuity; - this->audio_decoder.dispose = a52dec_dispose; - this->stream = stream; - this->class = (a52dec_class_t *) class_gen; - - /* int i; */ - - this->audio_caps = stream->audio_out->get_capabilities(stream->audio_out); - this->syncword = 0; - this->sync_state = 0; - this->output_open = 0; - this->pts = 0; - this->pts_list[0] = 0; - this->pts_list_position = 0; - - if( !this->a52_state ) - this->a52_state = a52_init (xine_mm_accel()); - - /* - * find out if this driver supports a52 output - * or, if not, how many channels we've got - */ - - if (this->audio_caps & AO_CAP_MODE_A52) - this->bypass_mode = 1; - else { - this->bypass_mode = 0; - - this->a52_flags_map[A52_MONO] = A52_MONO; - this->a52_flags_map[A52_STEREO] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - this->a52_flags_map[A52_3F] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - this->a52_flags_map[A52_2F1R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - this->a52_flags_map[A52_3F1R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - this->a52_flags_map[A52_2F2R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - this->a52_flags_map[A52_3F2R] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - this->a52_flags_map[A52_DOLBY] = ((this->class->enable_surround_downmix ? A52_DOLBY : A52_STEREO)); - - this->ao_flags_map[A52_MONO] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_STEREO] = AO_CAP_MODE_STEREO; - this->ao_flags_map[A52_3F] = AO_CAP_MODE_STEREO; - this->ao_flags_map[A52_2F1R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[A52_3F1R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[A52_DOLBY] = AO_CAP_MODE_STEREO; - - /* find best mode */ - if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { - - this->a52_flags_map[A52_2F2R] = A52_2F2R; - this->a52_flags_map[A52_3F2R] = A52_3F2R | A52_LFE; - this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_5CHANNEL; - - } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) { - - this->a52_flags_map[A52_2F2R] = A52_2F2R; - this->a52_flags_map[A52_3F2R] = A52_3F2R; - this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_5CHANNEL; - - } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { - - this->a52_flags_map[A52_2F2R] = A52_2F2R; - this->a52_flags_map[A52_3F2R] = A52_2F2R | A52_LFE; - this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_4CHANNEL; - - } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) { - - this->a52_flags_map[A52_2F2R] = A52_2F2R; - this->a52_flags_map[A52_3F2R] = A52_2F2R; - - this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_4CHANNEL; - - /* else if (this->audio_caps & AO_CAP_MODE_STEREO) - defaults are ok */ - } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n")); - - this->a52_flags_map[A52_MONO] = A52_MONO; - this->a52_flags_map[A52_STEREO] = A52_MONO; - this->a52_flags_map[A52_3F] = A52_MONO; - this->a52_flags_map[A52_2F1R] = A52_MONO; - this->a52_flags_map[A52_3F1R] = A52_MONO; - this->a52_flags_map[A52_2F2R] = A52_MONO; - this->a52_flags_map[A52_3F2R] = A52_MONO; - this->a52_flags_map[A52_DOLBY] = A52_MONO; - - this->ao_flags_map[A52_MONO] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_STEREO] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_3F] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_2F1R] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_3F1R] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_2F2R] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_3F2R] = AO_CAP_MODE_MONO; - this->ao_flags_map[A52_DOLBY] = AO_CAP_MODE_MONO; - } - } - - /* - for (i = 0; i<8; i++) - this->a52_flags_map[i] |= A52_ADJUST_LEVEL; - */ -#ifdef DEBUG_A52 - a52file = open ("test.a52", O_CREAT | O_WRONLY | O_TRUNC, 0644); -#endif - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - lprintf ("get_identifier called\n"); - return "a/52dec"; -} - -static char *get_description (audio_decoder_class_t *this) { - lprintf ("get_description called\n"); - return "liba52 based a52 audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - lprintf ("dispose_class called\n"); - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - a52dec_class_t *this; - config_values_t *cfg; - - this = (a52dec_class_t *) xine_xmalloc (sizeof (a52dec_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - cfg = this->config = xine->config; - - this->a52_level = (float) cfg->register_range (cfg, "audio.a52.level", 100, - 0, 200, - _("A/52 volume"), - _("With A/52 audio, you can modify the volume " - "at the decoder level. This has the advantage " - "of the audio being already decoded for the " - "specified volume, so later operations like " - "channel downmixing will work on an audio stream " - "of the given volume."), - 10, a52_level_change_cb, this) / 100.0; - this->disable_dynrng_compress = !cfg->register_bool (cfg, "audio.a52.dynamic_range", 0, - _("use A/52 dynamic range compression"), - _("Dynamic range compression limits the dynamic " - "range of the audio. This means making the loud " - "sounds softer, and the soft sounds louder, so you can " - "more easily listen to the audio in a noisy " - "environment without disturbing anyone."), - 0, dynrng_compress_change_cb, this); - this->enable_surround_downmix = cfg->register_bool (cfg, "audio.a52.surround_downmix", 0, - _("downmix audio to 2 channel surround stereo"), - _("When you want to listen to multichannel surround " - "sound, but you have only two speakers or a " - "surround decoder or amplifier which does some " - "sort of matrix surround decoding like prologic, " - "you should enable this option so that the " - "additional channels are mixed into the stereo " - "signal."), - 0, surround_downmix_change_cb, this); - lprintf ("init_plugin called\n"); - return this; -} - -static void a52_level_change_cb(void *this_gen, xine_cfg_entry_t *entry) -{ - ((a52dec_class_t *)this_gen)->a52_level = entry->num_value / 100.0; -} - -static void dynrng_compress_change_cb(void *this_gen, xine_cfg_entry_t *entry) -{ - ((a52dec_class_t *)this_gen)->disable_dynrng_compress = !entry->num_value; -} - -static void surround_downmix_change_cb(void *this_gen, xine_cfg_entry_t *entry) -{ - ((a52dec_class_t *)this_gen)->enable_surround_downmix = entry->num_value; -} - - -static uint32_t audio_types[] = { - BUF_AUDIO_A52, - BUF_AUDIO_DNET, - 0 - }; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER | PLUGIN_MUST_PRELOAD, 15, "a/52", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; -- cgit v1.2.3 From ee13bbd57e1f5722a3b5e2cdbefb33b5108b36cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 21:16:28 +0200 Subject: Rename xine_decoder.c to xine_dts_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libdts/xine_decoder.c => src/libdts/xine_dts_decoder.c --- src/libdts/Makefile.am | 8 +- src/libdts/xine_decoder.c | 614 ------------------------------------------ src/libdts/xine_dts_decoder.c | 614 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 617 insertions(+), 619 deletions(-) delete mode 100644 src/libdts/xine_decoder.c create mode 100644 src/libdts/xine_dts_decoder.c (limited to 'src') diff --git a/src/libdts/Makefile.am b/src/libdts/Makefile.am index 4cf54884f..207755f1f 100644 --- a/src/libdts/Makefile.am +++ b/src/libdts/Makefile.am @@ -1,12 +1,10 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) - if DTS dts_module = xineplug_decode_dts.la endif -lib_LTLIBRARIES = $(dts_module) +xineplug_LTLIBRARIES = $(dts_module) if EXTERNAL_LIBDTS fnsa = @@ -16,9 +14,9 @@ fnsa = -fno-strict-aliasing internal_sources = bitstream.c downmix.c parse.c endif -xineplug_decode_dts_la_SOURCES = xine_decoder.c $(internal_sources) +xineplug_decode_dts_la_SOURCES = xine_dts_decoder.c $(internal_sources) xineplug_decode_dts_la_CFLAGS = $(LIBDTS_CFLAGS) $(VISIBILITY_FLAG) $(fnsa) -xineplug_decode_dts_la_LDFLAGS = -avoid-version -module +xineplug_decode_dts_la_LDFLAGS = $(xineplug_ldflags) if EXTERNAL_LIBDTS xineplug_decode_dts_la_LIBADD = $(XINE_LIB) $(LIBDTS_LIBS) -lm diff --git a/src/libdts/xine_decoder.c b/src/libdts/xine_decoder.c deleted file mode 100644 index 902d8c5b6..000000000 --- a/src/libdts/xine_decoder.c +++ /dev/null @@ -1,614 +0,0 @@ -/* - * Copyright (C) 2000-2005 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: xine_decoder.c,v 1.67 2007/02/20 00:34:57 dgp85 Exp $ - * - * 04-09-2001 DTS passtrough (C) Joachim Koenig - * 09-12-2001 DTS passthrough inprovements (C) James Courtier-Dutton - * - */ - -#ifndef __sun -/* required for swab() */ -#define _XOPEN_SOURCE 500 -#endif -/* avoid compiler warnings */ -#define _BSD_SOURCE 1 - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "libdts" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "xineutils.h" -#include "audio_out.h" -#include "buffer.h" -#include "dts.h" - -#define MAX_AC5_FRAME 4096 - -typedef struct { - audio_decoder_class_t decoder_class; -} dts_class_t; - -typedef struct { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - audio_decoder_class_t *class; - - dts_state_t *dts_state; - int64_t pts; - - int audio_caps; - int sync_state; - int ac5_length, ac5_pcm_length, frame_todo; - uint32_t syncdword; - uint8_t frame_buffer[MAX_AC5_FRAME]; - uint8_t *frame_ptr; - - int output_open; - - int bypass_mode; - int dts_flags; - int dts_sample_rate; - int dts_bit_rate; - int dts_flags_map[11]; /* Convert from stream dts_flags to the dts_flags we want from the dts downmixer */ - int ao_flags_map[11]; /* Convert from the xine AO_CAP's to dts_flags. */ - int have_lfe; - - -} dts_decoder_t; - -static void dts_reset (audio_decoder_t *this_gen); -static void dts_discontinuity (audio_decoder_t *this_gen); - -static void dts_reset (audio_decoder_t *this_gen) { - - /* dts_decoder_t *this = (dts_decoder_t *) this_gen; */ - -} - -static void dts_discontinuity (audio_decoder_t *this_gen) { -} - -#if 0 -static inline int16_t blah (int32_t i) { - - if (i > 0x43c07fff) - return 32767; - else if (i < 0x43bf8000) - return -32768; - else - return i - 0x43c00000; -} -static inline void float_to_int (float * _f, int16_t * s16, int num_channels) { - int i; - int32_t * f = (int32_t *) _f; /* XXX assumes IEEE float format */ - - for (i = 0; i < 256; i++) { - s16[num_channels*i] = blah (f[i]); - } -} -#endif - -static inline void float_to_int (float * _f, int16_t * s16, int num_channels) { - int i; - float f; - for (i = 0; i < 256; i++) { - f = _f[i] * 32767; - if (f > INT16_MAX) f = INT16_MAX; - if (f < INT16_MIN) f = INT16_MIN; - s16[num_channels*i] = f; - /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */ - } -} - -static inline void mute_channel (int16_t * s16, int num_channels) { - int i; - - for (i = 0; i < 256; i++) { - s16[num_channels*i] = 0; - } -} - -static void dts_decode_frame (dts_decoder_t *this, int64_t pts, int preview_mode) { - - audio_buffer_t *audio_buffer; - uint32_t ac5_spdif_type=0; - int output_mode = AO_CAP_MODE_STEREO; - uint8_t *data_out; - uint8_t *data_in = this->frame_buffer; - - lprintf("decode_frame\n"); - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - audio_buffer->vpts = pts; - - if(this->bypass_mode) { - /* SPDIF digital output */ - if (!this->output_open) { - this->output_open = (this->stream->audio_out->open (this->stream->audio_out, this->stream, - 16, this->dts_sample_rate, - AO_CAP_MODE_AC5)); - } - - if (!this->output_open) - return; - - data_out=(uint8_t *) audio_buffer->mem; - if (this->ac5_length > 8191) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: ac5_length too long\n"); - this->ac5_pcm_length = 0; - } - - switch (this->ac5_pcm_length) { - case 512: - ac5_spdif_type = 0x0b; /* DTS-1 (512-sample bursts) */ - break; - case 1024: - ac5_spdif_type = 0x0c; /* DTS-1 (1024-sample bursts) */ - break; - case 2048: - ac5_spdif_type = 0x0d; /* DTS-1 (2048-sample bursts) */ - break; - default: - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "libdts: DTS %i-sample bursts not supported\n", this->ac5_pcm_length); - return; - } - -#ifdef LOG_DEBUG - { - int i; - printf("libdts: DTS frame type=%d\n",data_in[4] >> 7); - printf("libdts: DTS deficit frame count=%d\n",(data_in[4] & 0x7f) >> 2); - printf("libdts: DTS AC5 PCM samples=%d\n",ac5_pcm_samples); - printf("libdts: DTS AC5 length=%d\n",this->ac5_length); - printf("libdts: DTS AC5 bitrate=%d\n",((data_in[8] & 0x03) << 4) | (data_in[8] >> 4)); - printf("libdts: DTS AC5 spdif type=%d\n", ac5_spdif_type); - - printf("libdts: "); - for(i=2000;i<2048;i++) { - printf("%02x ",data_in[i]); - } - printf("\n"); - } -#endif - - lprintf("length=%d pts=%"PRId64"\n",this->ac5_pcm_length,audio_buffer->vpts); - - audio_buffer->num_frames = this->ac5_pcm_length; - - data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */ - data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */ - data_out[4] = ac5_spdif_type; /* DTS data */ - data_out[5] = 0; /* Unknown */ - data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */ - data_out[7] = ((this->ac5_length ) >> 5) & 0xff; - - if( this->ac5_pcm_length ) { - if( this->ac5_pcm_length % 2) { - swab(data_in, &data_out[8], this->ac5_length ); - } else { - swab(data_in, &data_out[8], this->ac5_length + 1); - } - } - } else { - /* Software decode */ - int i, dts_output_flags; - int16_t *int_samples = audio_buffer->mem; - int number_of_dts_blocks; - - level_t level = 1.0; - sample_t *samples; - - dts_output_flags = this->dts_flags_map[this->dts_flags & DTS_CHANNEL_MASK]; - - if(dts_frame(this->dts_state, data_in, &dts_output_flags, &level, 0)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: dts_frame error\n"); - return; - } - - this->have_lfe = dts_output_flags & DTS_LFE; - if (this->have_lfe) - if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { - output_mode = AO_CAP_MODE_5_1CHANNEL; - } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { - output_mode = AO_CAP_MODE_4_1CHANNEL; - } else { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: WHAT DO I DO!!!\n"); - output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK]; - } - else - output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK]; - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream, - 16, this->dts_sample_rate, - output_mode); - } - - if (!this->output_open) - return; - number_of_dts_blocks = dts_blocks_num (this->dts_state); - audio_buffer->num_frames = 256*number_of_dts_blocks; - for(i = 0; i < number_of_dts_blocks; i++) { - if(dts_block(this->dts_state)) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "libdts: dts_block error on audio channel %d\n", i); - audio_buffer->num_frames = 0; - break; - } - - samples = dts_samples(this->dts_state); - switch (output_mode) { - case AO_CAP_MODE_MONO: - float_to_int (&samples[0], int_samples+(i*256), 1); - break; - case AO_CAP_MODE_STEREO: - /* Tested, working. */ - float_to_int (&samples[0*256], int_samples+(i*256*2), 2); /* L */ - float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); /* R */ - break; - case AO_CAP_MODE_4CHANNEL: - /* Tested, working */ - float_to_int (&samples[0*256], int_samples+(i*256*4), 4); /* L */ - float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /* R */ - float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */ - float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */ - break; - case AO_CAP_MODE_4_1CHANNEL: - /* Tested, working */ - float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /* L */ - float_to_int (&samples[1*256], int_samples+(i*256*6)+1, 6); /* R */ - float_to_int (&samples[2*256], int_samples+(i*256*6)+2, 6); /* RL */ - float_to_int (&samples[3*256], int_samples+(i*256*6)+3, 6); /* RR */ - float_to_int (&samples[4*256], int_samples+(i*256*6)+5, 6); /* LFE */ - mute_channel ( int_samples+(i*256*6)+4, 6); /* C */ - break; - case AO_CAP_MODE_5CHANNEL: - /* Tested, working */ - float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */ - float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ - float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ - float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ - float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ - mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */ - break; - case AO_CAP_MODE_5_1CHANNEL: - float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */ - float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ - float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ - float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ - float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ - float_to_int (&samples[5*256], int_samples+(i*256*6)+5, 6); /* LFE */ /* Not working yet */ - break; - default: - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: help - unsupported mode %08x\n", output_mode); - } - } - } - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - -} - -static void dts_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - dts_decoder_t *this = (dts_decoder_t *) this_gen; - uint8_t *current = (uint8_t *)buf->content; - uint8_t *sync_start=current + 1; - uint8_t *end = buf->content + buf->size; - - lprintf("decode_data\n"); - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - if (buf->decoder_flags & BUF_FLAG_STDHEADER) - return; - - lprintf ("processing...state %d\n", this->sync_state); - - while (current < end) { - switch (this->sync_state) { - case 0: /* Looking for sync header */ - this->syncdword = (this->syncdword << 8) | *current++; -/* - if ((this->syncdword == 0xff1f00e8) || - (this->syncdword == 0x1fffe800) || - (this->syncdword == 0xfe7f0180) || - (this->syncdword == 0x7ffe8001) ) { -*/ - if ((this->syncdword == 0x7ffe8001)) { - - lprintf ("sync found: syncdword=0x%x\n", this->syncdword); - this->frame_buffer[0] = 0x7f; - this->frame_buffer[1] = 0xfe; - this->frame_buffer[2] = 0x80; - this->frame_buffer[3] = 0x01; - - this->sync_state = 1; - this->frame_ptr = this->frame_buffer+4; - this->pts = buf->pts; - break; - } - if ((this->syncdword == 0xff1f00e8)) { - - lprintf ("sync found: syncdword=0x%x\n", this->syncdword); - this->frame_buffer[0] = 0xff; - this->frame_buffer[1] = 0x1f; - this->frame_buffer[2] = 0x00; - this->frame_buffer[3] = 0xe8; - - this->sync_state = 1; - this->frame_ptr = this->frame_buffer+4; - this->pts = buf->pts; - break; - } - break; - - case 1: /* Looking for enough bytes for sync_info. */ - sync_start = current - 1; - *this->frame_ptr++ = *current++; - if ((this->frame_ptr - this->frame_buffer) > 19) { - int old_dts_flags = this->dts_flags; - int old_dts_sample_rate = this->dts_sample_rate; - int old_dts_bit_rate = this->dts_bit_rate; - - this->ac5_length = dts_syncinfo (this->dts_state, this->frame_buffer, - &this->dts_flags, - &this->dts_sample_rate, - &this->dts_bit_rate, &(this->ac5_pcm_length)); - lprintf("ac5_length=%d\n",this->ac5_length); - lprintf("dts_sample_rate=%d\n",this->dts_sample_rate); - - if ( (this->ac5_length < 80) || (this->ac5_length > MAX_AC5_FRAME) ) { /* Invalid dts ac5_pcm_length */ - this->syncdword = 0; - current = sync_start; - this->sync_state = 0; - break; - } - - lprintf("Frame length = %d\n",this->ac5_pcm_length); - - this->frame_todo = this->ac5_length - 20; - this->sync_state = 2; - if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) || - old_dts_flags != this->dts_flags || - old_dts_sample_rate != this->dts_sample_rate || - old_dts_bit_rate != this->dts_bit_rate) { - - switch (this->dts_flags & DTS_CHANNEL_MASK) { - case DTS_3F2R: - if (this->dts_flags & DTS_LFE) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.1"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.0"); - break; - case DTS_3F1R: - case DTS_2F2R: - if (this->dts_flags & DTS_LFE) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.1"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.0"); - break; - case DTS_2F1R: - case DTS_3F: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 3.0"); - break; - case DTS_STEREO: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 2.0 (stereo)"); - break; - case DTS_MONO: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 1.0"); - break; - default: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS"); - break; - } - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->dts_bit_rate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->dts_sample_rate); - } - } - break; - - case 2: /* Filling frame_buffer with sync_info bytes */ - *this->frame_ptr++ = *current++; - this->frame_todo--; - if (this->frame_todo < 1) { - this->sync_state = 3; - } else break; - - case 3: /* Ready for decode */ -#if 0 - dtsdec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW); -#else - dts_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW); -#endif - case 4: /* Clear up ready for next frame */ - this->pts = 0; - this->syncdword = 0; - this->sync_state = 0; - break; - default: /* No come here */ - break; - } - } -} - -static void dts_dispose (audio_decoder_t *this_gen) { - dts_decoder_t *this = (dts_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free (this); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - dts_decoder_t *this ; - - lprintf("open_plugin\n"); - - this = (dts_decoder_t *) xine_xmalloc (sizeof (dts_decoder_t)); - - this->audio_decoder.decode_data = dts_decode_data; - this->audio_decoder.reset = dts_reset; - this->audio_decoder.discontinuity = dts_discontinuity; - this->audio_decoder.dispose = dts_dispose; - - this->dts_state = dts_init(0); - this->audio_caps = stream->audio_out->get_capabilities(stream->audio_out); - if(this->audio_caps & AO_CAP_MODE_AC5) - this->bypass_mode = 1; - else { - this->bypass_mode = 0; - /* FIXME: Leave "DOLBY pro logic" downmix out for now. */ - - this->dts_flags_map[DTS_MONO] = DTS_MONO; - this->dts_flags_map[DTS_STEREO] = DTS_STEREO; - this->dts_flags_map[DTS_3F] = DTS_STEREO; - this->dts_flags_map[DTS_2F1R] = DTS_STEREO; - this->dts_flags_map[DTS_3F1R] = DTS_STEREO; - this->dts_flags_map[DTS_2F2R] = DTS_STEREO; - this->dts_flags_map[DTS_3F2R] = DTS_STEREO; - - this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_STEREO; - this->ao_flags_map[DTS_3F] = AO_CAP_MODE_STEREO; - this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_STEREO; - this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_STEREO; - - /* find best mode */ - if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { - - this->dts_flags_map[DTS_2F2R] = DTS_2F2R; - this->dts_flags_map[DTS_3F2R] = DTS_3F2R | DTS_LFE; - this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL; - - } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) { - - this->dts_flags_map[DTS_2F2R] = DTS_2F2R; - this->dts_flags_map[DTS_3F2R] = DTS_3F2R; - this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL; - - } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { - - this->dts_flags_map[DTS_2F2R] = DTS_2F2R; - this->dts_flags_map[DTS_3F2R] = DTS_2F2R | DTS_LFE; - this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL; - - } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) { - - this->dts_flags_map[DTS_2F2R] = DTS_2F2R; - this->dts_flags_map[DTS_3F2R] = DTS_2F2R; - - this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; - this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL; - - /* else if (this->audio_caps & AO_CAP_MODE_STEREO) - defaults are ok */ - } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n")); - - this->dts_flags_map[DTS_MONO] = DTS_MONO; - this->dts_flags_map[DTS_STEREO] = DTS_MONO; - this->dts_flags_map[DTS_3F] = DTS_MONO; - this->dts_flags_map[DTS_2F1R] = DTS_MONO; - this->dts_flags_map[DTS_3F1R] = DTS_MONO; - this->dts_flags_map[DTS_2F2R] = DTS_MONO; - this->dts_flags_map[DTS_3F2R] = DTS_MONO; - - this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_3F] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_MONO; - this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_MONO; - } - } - this->stream = stream; - this->class = class_gen; - this->output_open = 0; - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "DTS"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "DTS passthru audio format decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - lprintf("dispose_class\n"); - - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - dts_class_t *this ; - - lprintf("init_plugin\n"); - - this = (dts_class_t *) xine_xmalloc (sizeof (dts_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_DTS, 0 - }; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "dts", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libdts/xine_dts_decoder.c b/src/libdts/xine_dts_decoder.c new file mode 100644 index 000000000..902d8c5b6 --- /dev/null +++ b/src/libdts/xine_dts_decoder.c @@ -0,0 +1,614 @@ +/* + * Copyright (C) 2000-2005 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: xine_decoder.c,v 1.67 2007/02/20 00:34:57 dgp85 Exp $ + * + * 04-09-2001 DTS passtrough (C) Joachim Koenig + * 09-12-2001 DTS passthrough inprovements (C) James Courtier-Dutton + * + */ + +#ifndef __sun +/* required for swab() */ +#define _XOPEN_SOURCE 500 +#endif +/* avoid compiler warnings */ +#define _BSD_SOURCE 1 + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "libdts" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "xineutils.h" +#include "audio_out.h" +#include "buffer.h" +#include "dts.h" + +#define MAX_AC5_FRAME 4096 + +typedef struct { + audio_decoder_class_t decoder_class; +} dts_class_t; + +typedef struct { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + audio_decoder_class_t *class; + + dts_state_t *dts_state; + int64_t pts; + + int audio_caps; + int sync_state; + int ac5_length, ac5_pcm_length, frame_todo; + uint32_t syncdword; + uint8_t frame_buffer[MAX_AC5_FRAME]; + uint8_t *frame_ptr; + + int output_open; + + int bypass_mode; + int dts_flags; + int dts_sample_rate; + int dts_bit_rate; + int dts_flags_map[11]; /* Convert from stream dts_flags to the dts_flags we want from the dts downmixer */ + int ao_flags_map[11]; /* Convert from the xine AO_CAP's to dts_flags. */ + int have_lfe; + + +} dts_decoder_t; + +static void dts_reset (audio_decoder_t *this_gen); +static void dts_discontinuity (audio_decoder_t *this_gen); + +static void dts_reset (audio_decoder_t *this_gen) { + + /* dts_decoder_t *this = (dts_decoder_t *) this_gen; */ + +} + +static void dts_discontinuity (audio_decoder_t *this_gen) { +} + +#if 0 +static inline int16_t blah (int32_t i) { + + if (i > 0x43c07fff) + return 32767; + else if (i < 0x43bf8000) + return -32768; + else + return i - 0x43c00000; +} +static inline void float_to_int (float * _f, int16_t * s16, int num_channels) { + int i; + int32_t * f = (int32_t *) _f; /* XXX assumes IEEE float format */ + + for (i = 0; i < 256; i++) { + s16[num_channels*i] = blah (f[i]); + } +} +#endif + +static inline void float_to_int (float * _f, int16_t * s16, int num_channels) { + int i; + float f; + for (i = 0; i < 256; i++) { + f = _f[i] * 32767; + if (f > INT16_MAX) f = INT16_MAX; + if (f < INT16_MIN) f = INT16_MIN; + s16[num_channels*i] = f; + /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */ + } +} + +static inline void mute_channel (int16_t * s16, int num_channels) { + int i; + + for (i = 0; i < 256; i++) { + s16[num_channels*i] = 0; + } +} + +static void dts_decode_frame (dts_decoder_t *this, int64_t pts, int preview_mode) { + + audio_buffer_t *audio_buffer; + uint32_t ac5_spdif_type=0; + int output_mode = AO_CAP_MODE_STEREO; + uint8_t *data_out; + uint8_t *data_in = this->frame_buffer; + + lprintf("decode_frame\n"); + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + audio_buffer->vpts = pts; + + if(this->bypass_mode) { + /* SPDIF digital output */ + if (!this->output_open) { + this->output_open = (this->stream->audio_out->open (this->stream->audio_out, this->stream, + 16, this->dts_sample_rate, + AO_CAP_MODE_AC5)); + } + + if (!this->output_open) + return; + + data_out=(uint8_t *) audio_buffer->mem; + if (this->ac5_length > 8191) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: ac5_length too long\n"); + this->ac5_pcm_length = 0; + } + + switch (this->ac5_pcm_length) { + case 512: + ac5_spdif_type = 0x0b; /* DTS-1 (512-sample bursts) */ + break; + case 1024: + ac5_spdif_type = 0x0c; /* DTS-1 (1024-sample bursts) */ + break; + case 2048: + ac5_spdif_type = 0x0d; /* DTS-1 (2048-sample bursts) */ + break; + default: + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "libdts: DTS %i-sample bursts not supported\n", this->ac5_pcm_length); + return; + } + +#ifdef LOG_DEBUG + { + int i; + printf("libdts: DTS frame type=%d\n",data_in[4] >> 7); + printf("libdts: DTS deficit frame count=%d\n",(data_in[4] & 0x7f) >> 2); + printf("libdts: DTS AC5 PCM samples=%d\n",ac5_pcm_samples); + printf("libdts: DTS AC5 length=%d\n",this->ac5_length); + printf("libdts: DTS AC5 bitrate=%d\n",((data_in[8] & 0x03) << 4) | (data_in[8] >> 4)); + printf("libdts: DTS AC5 spdif type=%d\n", ac5_spdif_type); + + printf("libdts: "); + for(i=2000;i<2048;i++) { + printf("%02x ",data_in[i]); + } + printf("\n"); + } +#endif + + lprintf("length=%d pts=%"PRId64"\n",this->ac5_pcm_length,audio_buffer->vpts); + + audio_buffer->num_frames = this->ac5_pcm_length; + + data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */ + data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */ + data_out[4] = ac5_spdif_type; /* DTS data */ + data_out[5] = 0; /* Unknown */ + data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */ + data_out[7] = ((this->ac5_length ) >> 5) & 0xff; + + if( this->ac5_pcm_length ) { + if( this->ac5_pcm_length % 2) { + swab(data_in, &data_out[8], this->ac5_length ); + } else { + swab(data_in, &data_out[8], this->ac5_length + 1); + } + } + } else { + /* Software decode */ + int i, dts_output_flags; + int16_t *int_samples = audio_buffer->mem; + int number_of_dts_blocks; + + level_t level = 1.0; + sample_t *samples; + + dts_output_flags = this->dts_flags_map[this->dts_flags & DTS_CHANNEL_MASK]; + + if(dts_frame(this->dts_state, data_in, &dts_output_flags, &level, 0)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: dts_frame error\n"); + return; + } + + this->have_lfe = dts_output_flags & DTS_LFE; + if (this->have_lfe) + if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { + output_mode = AO_CAP_MODE_5_1CHANNEL; + } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { + output_mode = AO_CAP_MODE_4_1CHANNEL; + } else { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: WHAT DO I DO!!!\n"); + output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK]; + } + else + output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK]; + + if (!this->output_open) { + this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream, + 16, this->dts_sample_rate, + output_mode); + } + + if (!this->output_open) + return; + number_of_dts_blocks = dts_blocks_num (this->dts_state); + audio_buffer->num_frames = 256*number_of_dts_blocks; + for(i = 0; i < number_of_dts_blocks; i++) { + if(dts_block(this->dts_state)) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "libdts: dts_block error on audio channel %d\n", i); + audio_buffer->num_frames = 0; + break; + } + + samples = dts_samples(this->dts_state); + switch (output_mode) { + case AO_CAP_MODE_MONO: + float_to_int (&samples[0], int_samples+(i*256), 1); + break; + case AO_CAP_MODE_STEREO: + /* Tested, working. */ + float_to_int (&samples[0*256], int_samples+(i*256*2), 2); /* L */ + float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); /* R */ + break; + case AO_CAP_MODE_4CHANNEL: + /* Tested, working */ + float_to_int (&samples[0*256], int_samples+(i*256*4), 4); /* L */ + float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /* R */ + float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */ + float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */ + break; + case AO_CAP_MODE_4_1CHANNEL: + /* Tested, working */ + float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /* L */ + float_to_int (&samples[1*256], int_samples+(i*256*6)+1, 6); /* R */ + float_to_int (&samples[2*256], int_samples+(i*256*6)+2, 6); /* RL */ + float_to_int (&samples[3*256], int_samples+(i*256*6)+3, 6); /* RR */ + float_to_int (&samples[4*256], int_samples+(i*256*6)+5, 6); /* LFE */ + mute_channel ( int_samples+(i*256*6)+4, 6); /* C */ + break; + case AO_CAP_MODE_5CHANNEL: + /* Tested, working */ + float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */ + float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ + float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ + float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ + float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ + mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */ + break; + case AO_CAP_MODE_5_1CHANNEL: + float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */ + float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */ + float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */ + float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */ + float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */ + float_to_int (&samples[5*256], int_samples+(i*256*6)+5, 6); /* LFE */ /* Not working yet */ + break; + default: + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: help - unsupported mode %08x\n", output_mode); + } + } + } + + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + + +} + +static void dts_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + dts_decoder_t *this = (dts_decoder_t *) this_gen; + uint8_t *current = (uint8_t *)buf->content; + uint8_t *sync_start=current + 1; + uint8_t *end = buf->content + buf->size; + + lprintf("decode_data\n"); + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + if (buf->decoder_flags & BUF_FLAG_STDHEADER) + return; + + lprintf ("processing...state %d\n", this->sync_state); + + while (current < end) { + switch (this->sync_state) { + case 0: /* Looking for sync header */ + this->syncdword = (this->syncdword << 8) | *current++; +/* + if ((this->syncdword == 0xff1f00e8) || + (this->syncdword == 0x1fffe800) || + (this->syncdword == 0xfe7f0180) || + (this->syncdword == 0x7ffe8001) ) { +*/ + if ((this->syncdword == 0x7ffe8001)) { + + lprintf ("sync found: syncdword=0x%x\n", this->syncdword); + this->frame_buffer[0] = 0x7f; + this->frame_buffer[1] = 0xfe; + this->frame_buffer[2] = 0x80; + this->frame_buffer[3] = 0x01; + + this->sync_state = 1; + this->frame_ptr = this->frame_buffer+4; + this->pts = buf->pts; + break; + } + if ((this->syncdword == 0xff1f00e8)) { + + lprintf ("sync found: syncdword=0x%x\n", this->syncdword); + this->frame_buffer[0] = 0xff; + this->frame_buffer[1] = 0x1f; + this->frame_buffer[2] = 0x00; + this->frame_buffer[3] = 0xe8; + + this->sync_state = 1; + this->frame_ptr = this->frame_buffer+4; + this->pts = buf->pts; + break; + } + break; + + case 1: /* Looking for enough bytes for sync_info. */ + sync_start = current - 1; + *this->frame_ptr++ = *current++; + if ((this->frame_ptr - this->frame_buffer) > 19) { + int old_dts_flags = this->dts_flags; + int old_dts_sample_rate = this->dts_sample_rate; + int old_dts_bit_rate = this->dts_bit_rate; + + this->ac5_length = dts_syncinfo (this->dts_state, this->frame_buffer, + &this->dts_flags, + &this->dts_sample_rate, + &this->dts_bit_rate, &(this->ac5_pcm_length)); + lprintf("ac5_length=%d\n",this->ac5_length); + lprintf("dts_sample_rate=%d\n",this->dts_sample_rate); + + if ( (this->ac5_length < 80) || (this->ac5_length > MAX_AC5_FRAME) ) { /* Invalid dts ac5_pcm_length */ + this->syncdword = 0; + current = sync_start; + this->sync_state = 0; + break; + } + + lprintf("Frame length = %d\n",this->ac5_pcm_length); + + this->frame_todo = this->ac5_length - 20; + this->sync_state = 2; + if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) || + old_dts_flags != this->dts_flags || + old_dts_sample_rate != this->dts_sample_rate || + old_dts_bit_rate != this->dts_bit_rate) { + + switch (this->dts_flags & DTS_CHANNEL_MASK) { + case DTS_3F2R: + if (this->dts_flags & DTS_LFE) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.1"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.0"); + break; + case DTS_3F1R: + case DTS_2F2R: + if (this->dts_flags & DTS_LFE) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.1"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.0"); + break; + case DTS_2F1R: + case DTS_3F: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 3.0"); + break; + case DTS_STEREO: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 2.0 (stereo)"); + break; + case DTS_MONO: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 1.0"); + break; + default: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS"); + break; + } + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->dts_bit_rate); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->dts_sample_rate); + } + } + break; + + case 2: /* Filling frame_buffer with sync_info bytes */ + *this->frame_ptr++ = *current++; + this->frame_todo--; + if (this->frame_todo < 1) { + this->sync_state = 3; + } else break; + + case 3: /* Ready for decode */ +#if 0 + dtsdec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW); +#else + dts_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW); +#endif + case 4: /* Clear up ready for next frame */ + this->pts = 0; + this->syncdword = 0; + this->sync_state = 0; + break; + default: /* No come here */ + break; + } + } +} + +static void dts_dispose (audio_decoder_t *this_gen) { + dts_decoder_t *this = (dts_decoder_t *) this_gen; + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + free (this); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + dts_decoder_t *this ; + + lprintf("open_plugin\n"); + + this = (dts_decoder_t *) xine_xmalloc (sizeof (dts_decoder_t)); + + this->audio_decoder.decode_data = dts_decode_data; + this->audio_decoder.reset = dts_reset; + this->audio_decoder.discontinuity = dts_discontinuity; + this->audio_decoder.dispose = dts_dispose; + + this->dts_state = dts_init(0); + this->audio_caps = stream->audio_out->get_capabilities(stream->audio_out); + if(this->audio_caps & AO_CAP_MODE_AC5) + this->bypass_mode = 1; + else { + this->bypass_mode = 0; + /* FIXME: Leave "DOLBY pro logic" downmix out for now. */ + + this->dts_flags_map[DTS_MONO] = DTS_MONO; + this->dts_flags_map[DTS_STEREO] = DTS_STEREO; + this->dts_flags_map[DTS_3F] = DTS_STEREO; + this->dts_flags_map[DTS_2F1R] = DTS_STEREO; + this->dts_flags_map[DTS_3F1R] = DTS_STEREO; + this->dts_flags_map[DTS_2F2R] = DTS_STEREO; + this->dts_flags_map[DTS_3F2R] = DTS_STEREO; + + this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_STEREO; + this->ao_flags_map[DTS_3F] = AO_CAP_MODE_STEREO; + this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_STEREO; + this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_STEREO; + + /* find best mode */ + if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) { + + this->dts_flags_map[DTS_2F2R] = DTS_2F2R; + this->dts_flags_map[DTS_3F2R] = DTS_3F2R | DTS_LFE; + this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL; + + } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) { + + this->dts_flags_map[DTS_2F2R] = DTS_2F2R; + this->dts_flags_map[DTS_3F2R] = DTS_3F2R; + this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL; + + } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) { + + this->dts_flags_map[DTS_2F2R] = DTS_2F2R; + this->dts_flags_map[DTS_3F2R] = DTS_2F2R | DTS_LFE; + this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL; + + } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) { + + this->dts_flags_map[DTS_2F2R] = DTS_2F2R; + this->dts_flags_map[DTS_3F2R] = DTS_2F2R; + + this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL; + this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL; + + /* else if (this->audio_caps & AO_CAP_MODE_STEREO) + defaults are ok */ + } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n")); + + this->dts_flags_map[DTS_MONO] = DTS_MONO; + this->dts_flags_map[DTS_STEREO] = DTS_MONO; + this->dts_flags_map[DTS_3F] = DTS_MONO; + this->dts_flags_map[DTS_2F1R] = DTS_MONO; + this->dts_flags_map[DTS_3F1R] = DTS_MONO; + this->dts_flags_map[DTS_2F2R] = DTS_MONO; + this->dts_flags_map[DTS_3F2R] = DTS_MONO; + + this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_3F] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_MONO; + this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_MONO; + } + } + this->stream = stream; + this->class = class_gen; + this->output_open = 0; + + return &this->audio_decoder; +} + +static char *get_identifier (audio_decoder_class_t *this) { + return "DTS"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "DTS passthru audio format decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + lprintf("dispose_class\n"); + + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + dts_class_t *this ; + + lprintf("init_plugin\n"); + + this = (dts_class_t *) xine_xmalloc (sizeof (dts_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_DTS, 0 + }; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "dts", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From d9719dbf52e99600c5e105efa7f828152c6cfe19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 21:18:18 +0200 Subject: Rename xine_decoder.c to xine_faad_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libfaad/xine_decoder.c => src/libfaad/xine_faad_decoder.c --- src/libfaad/Makefile.am | 8 +- src/libfaad/xine_decoder.c | 485 ---------------------------------------- src/libfaad/xine_faad_decoder.c | 485 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 488 insertions(+), 490 deletions(-) delete mode 100644 src/libfaad/xine_decoder.c create mode 100644 src/libfaad/xine_faad_decoder.c (limited to 'src') diff --git a/src/libfaad/Makefile.am b/src/libfaad/Makefile.am index dcc57792a..d1a4ed865 100644 --- a/src/libfaad/Makefile.am +++ b/src/libfaad/Makefile.am @@ -2,13 +2,11 @@ include $(top_srcdir)/misc/Makefile.common SUBDIRS = codebook -libdir = $(XINE_PLUGINDIR) - if BUILD_FAAD faad_module = xineplug_decode_faad.la endif -lib_LTLIBRARIES = $(faad_module) +xineplug_LTLIBRARIES = $(faad_module) VPATH = @srcdir@:@srcdir@/codebook: @@ -52,9 +50,9 @@ xineplug_decode_faad_la_SOURCES = \ ssr_ipqf.c \ syntax.c \ tns.c \ - xine_decoder.c + xine_faad_decoder.c -xineplug_decode_faad_la_LDFLAGS = -avoid-version -module +xineplug_decode_faad_la_LDFLAGS = $(xineplug_ldflags) xineplug_decode_faad_la_LIBADD = -lm $(XINE_LIB) noinst_HEADERS = \ diff --git a/src/libfaad/xine_decoder.c b/src/libfaad/xine_decoder.c deleted file mode 100644 index aa528a34d..000000000 --- a/src/libfaad/xine_decoder.c +++ /dev/null @@ -1,485 +0,0 @@ -/* - * Copyright (C) 2000-2005 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.49 2007/02/20 00:34:57 dgp85 Exp $ - * - */ - -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "libfaad" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "common.h" -#include "structs.h" -#include "decoder.h" -#include "syntax.h" - -#define FAAD_MIN_STREAMSIZE 768 /* 6144 bits/channel */ - -typedef struct { - audio_decoder_class_t decoder_class; -} faad_class_t; - -typedef struct faad_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - /* faad2 stuff */ - NeAACDecHandle faac_dec; - NeAACDecConfigurationPtr faac_cfg; - NeAACDecFrameInfo faac_finfo; - int faac_failed; - - int raw_mode; - - unsigned char *buf; - int size; - int rec_audio_src_size; - int max_audio_src_size; - int pts; - - unsigned char *dec_config; - int dec_config_size; - - uint32_t rate; - int bits_per_sample; - unsigned char num_channels; - int sbr; - uint32_t ao_cap_mode; - - int output_open; - - unsigned long total_time; - unsigned long total_data; -} faad_decoder_t; - - -static void faad_reset (audio_decoder_t *this_gen) { - - faad_decoder_t *this = (faad_decoder_t *) this_gen; - this->size = 0; -} - -static void faad_meta_info_set ( faad_decoder_t *this ) { - switch (this->num_channels) { - case 1: - if (this->faac_finfo.sbr == SBR_UPSAMPLED) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "HE-AAC 1.0 (libfaad)"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "AAC 1.0 (libfaad)"); - break; - case 2: - /* check if this is downmixed 5.1 */ - if (!this->faac_cfg || !this->faac_cfg->downMatrix) { - if (this->faac_finfo.sbr == SBR_UPSAMPLED) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "HE-AAC 2.0 (libfaad)"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "AAC 2.0 (libfaad)"); - break; - } - case 6: - if (this->faac_finfo.sbr == SBR_UPSAMPLED) - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "HE-AAC 5.1 (libfaad)"); - else - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "AAC 5.1 (libfaad)"); - break; - } -} - -static int faad_open_dec( faad_decoder_t *this ) { - int used; - - this->faac_dec = NeAACDecOpen(); - if( !this->faac_dec ) { - xprintf( this->stream->xine, XINE_VERBOSITY_LOG, - _("libfaad: libfaad NeAACDecOpen() failed.\n")); - this->faac_failed++; - } else { - if( this->dec_config ) { - used = NeAACDecInit2(this->faac_dec, this->dec_config, this->dec_config_size, - &this->rate, &this->num_channels); - - if( used < 0 ) { - xprintf( this->stream->xine, XINE_VERBOSITY_LOG, - _("libfaad: libfaad NeAACDecInit2 failed.\n")); - this->faac_failed++; - } else - lprintf( "NeAACDecInit2 returned rate=%"PRId32" channels=%d\n", - this->rate, this->num_channels ); - } else { - used = NeAACDecInit(this->faac_dec, this->buf, this->size, - &this->rate, &this->num_channels); - - if( used < 0 ) { - xprintf ( this->stream->xine, XINE_VERBOSITY_LOG, - _("libfaad: libfaad NeAACDecInit failed.\n")); - this->faac_failed++; - } else { - lprintf( "NeAACDecInit() returned rate=%"PRId32" channels=%d (used=%d)\n", - this->rate, this->num_channels, used); - - this->size -= used; - memmove( this->buf, &this->buf[used], this->size ); - } - } - } - - if( !this->bits_per_sample ) - this->bits_per_sample = 16; - - if( this->faac_failed ) { - if( this->faac_dec ) { - NeAACDecClose( this->faac_dec ); - this->faac_dec = NULL; - } - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - } else { - faad_meta_info_set(this); - } - - return this->faac_failed; -} - -static int faad_open_output( faad_decoder_t *this ) { - this->rec_audio_src_size = this->num_channels * FAAD_MIN_STREAMSIZE; - - switch( this->num_channels ) { - case 1: - this->ao_cap_mode=AO_CAP_MODE_MONO; - break; - case 6: - if(this->stream->audio_out->get_capabilities(this->stream->audio_out) & - AO_CAP_MODE_5_1CHANNEL) { - this->ao_cap_mode = AO_CAP_MODE_5_1CHANNEL; - break; - } else { - this->faac_cfg = NeAACDecGetCurrentConfiguration(this->faac_dec); - this->faac_cfg->downMatrix = 1; - NeAACDecSetConfiguration(this->faac_dec, this->faac_cfg); - this->num_channels = 2; - } - case 2: - this->ao_cap_mode=AO_CAP_MODE_STEREO; - break; - } - - this->output_open = this->stream->audio_out->open (this->stream->audio_out, - this->stream, - this->bits_per_sample, - this->rate, - this->ao_cap_mode) ; - return this->output_open; -} - -static void faad_decode_audio ( faad_decoder_t *this, int end_frame ) { - int used, decoded, outsize; - uint8_t *sample_buffer; - uint8_t *inbuf; - audio_buffer_t *audio_buffer; - int sample_size = this->size; - - if( !this->faac_dec ) - return; - - inbuf = this->buf; - while( (!this->raw_mode && end_frame && this->size >= 10) || - (this->raw_mode && this->size >= this->rec_audio_src_size) ) { - - sample_buffer = NeAACDecDecode(this->faac_dec, - &this->faac_finfo, inbuf, sample_size); - - if( !sample_buffer ) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "libfaad: %s\n", NeAACDecGetErrorMessage(this->faac_finfo.error)); - used = 1; - } else { - used = this->faac_finfo.bytesconsumed; - - /* raw AAC parameters might only be known after decoding the first frame */ - if( !this->dec_config && - (this->num_channels != this->faac_finfo.channels || - this->rate != this->faac_finfo.samplerate) ) { - - this->num_channels = this->faac_finfo.channels; - this->rate = this->faac_finfo.samplerate; - - lprintf("faacDecDecode() returned rate=%"PRId32" channels=%d used=%d\n", - this->rate, this->num_channels, used); - - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - faad_open_output( this ); - - faad_meta_info_set( this ); - } - - /* faad doesn't tell us about sbr until after the first frame */ - if (this->sbr != this->faac_finfo.sbr) { - this->sbr = this->faac_finfo.sbr; - faad_meta_info_set( this ); - } - - /* estimate bitrate */ - this->total_time += (1000*this->faac_finfo.samples/(this->rate*this->num_channels)); - this->total_data += 8*used; - - if ((this->total_time > LONG_MAX) || (this->total_data > LONG_MAX)) { - this->total_time >>= 2; - this->total_data >>= 2; - } - - if (this->total_time) - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, - 1000*(this->total_data/this->total_time)); - - decoded = this->faac_finfo.samples * 2; /* 1 sample = 2 bytes */ - - lprintf("decoded %d/%d output %ld\n", - used, this->size, this->faac_finfo.samples ); - - while( decoded ) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - if( decoded < audio_buffer->mem_size ) - outsize = decoded; - else - outsize = audio_buffer->mem_size; - - xine_fast_memcpy( audio_buffer->mem, sample_buffer, outsize ); - - audio_buffer->num_frames = outsize / (this->num_channels*2); - audio_buffer->vpts = this->pts; - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - this->pts = 0; - decoded -= outsize; - sample_buffer += outsize; - } - } - - if(used >= this->size){ - this->size = 0; - } else { - this->size -= used; - inbuf += used; - } - - if( !this->raw_mode ) - this->size = 0; - } - - if( this->size ) - memmove( this->buf, inbuf, this->size); - -} - -static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - faad_decoder_t *this = (faad_decoder_t *) this_gen; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* store config information from ESDS mp4/qt atom */ - if( !this->faac_dec && (buf->decoder_flags & BUF_FLAG_SPECIAL) && - buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG ) { - - this->dec_config = xine_xmalloc(buf->decoder_info[2]); - this->dec_config_size = buf->decoder_info[2]; - memcpy(this->dec_config, buf->decoder_info_ptr[2], buf->decoder_info[2]); - - if( faad_open_dec(this) ) - return; - - this->raw_mode = 0; - } - - /* get audio parameters from file header - (may be overwritten by libfaad returned parameters) */ - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->rate=buf->decoder_info[1]; - this->bits_per_sample=buf->decoder_info[2] ; - this->num_channels=buf->decoder_info[3] ; - - if( buf->size > sizeof(xine_waveformatex) ) { - xine_waveformatex *wavex = (xine_waveformatex *) buf->content; - - if( wavex->cbSize > 0 ) { - this->dec_config = xine_xmalloc(wavex->cbSize); - this->dec_config_size = wavex->cbSize; - memcpy(this->dec_config, buf->content + sizeof(xine_waveformatex), - wavex->cbSize); - - if( faad_open_dec(this) ) - return; - - this->raw_mode = 0; - } - } - } else { - - lprintf ("decoding %d data bytes...\n", buf->size); - - if( (int)buf->size <= 0 || this->faac_failed ) - return; - - if( !this->size ) - this->pts = buf->pts; - - if( this->size + buf->size > this->max_audio_src_size ) { - this->max_audio_src_size = this->size + 2 * buf->size; - this->buf = realloc( this->buf, this->max_audio_src_size ); - } - - memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if( !this->faac_dec && faad_open_dec(this) ) - return; - - /* open audio device as needed */ - if (!this->output_open) { - faad_open_output( this ); - } - - faad_decode_audio(this, buf->decoder_flags & BUF_FLAG_FRAME_END ); - } -} - -static void faad_discontinuity (audio_decoder_t *this_gen) { -} - -static void faad_dispose (audio_decoder_t *this_gen) { - - faad_decoder_t *this = (faad_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - if( this->buf ) - free(this->buf); - this->buf = NULL; - this->size = 0; - this->max_audio_src_size = 0; - - if( this->dec_config ) - free(this->dec_config); - this->dec_config = NULL; - this->dec_config_size = 0; - - if( this->faac_dec ) - NeAACDecClose(this->faac_dec); - this->faac_dec = NULL; - this->faac_failed = 0; - - free (this); -} - - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - faad_decoder_t *this ; - - this = (faad_decoder_t *) xine_xmalloc (sizeof (faad_decoder_t)); - - this->audio_decoder.decode_data = faad_decode_data; - this->audio_decoder.reset = faad_reset; - this->audio_decoder.discontinuity = faad_discontinuity; - this->audio_decoder.dispose = faad_dispose; - - this->stream = stream; - this->output_open = 0; - this->raw_mode = 1; - this->faac_dec = NULL; - this->faac_failed = 0; - this->buf = NULL; - this->size = 0; - this->max_audio_src_size = 0; - this->dec_config = NULL; - this->dec_config_size = 0; - this->total_time = 0; - this->total_data = 0; - - this->rate = 0; - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "FAAD"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "Freeware Advanced Audio Decoder"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - faad_class_t *this ; - - this = (faad_class_t *) xine_xmalloc (sizeof (faad_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_AAC, 0 - }; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "faad", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libfaad/xine_faad_decoder.c b/src/libfaad/xine_faad_decoder.c new file mode 100644 index 000000000..aa528a34d --- /dev/null +++ b/src/libfaad/xine_faad_decoder.c @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2000-2005 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.49 2007/02/20 00:34:57 dgp85 Exp $ + * + */ + +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "libfaad" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" +#include "xineutils.h" +#include "common.h" +#include "structs.h" +#include "decoder.h" +#include "syntax.h" + +#define FAAD_MIN_STREAMSIZE 768 /* 6144 bits/channel */ + +typedef struct { + audio_decoder_class_t decoder_class; +} faad_class_t; + +typedef struct faad_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + /* faad2 stuff */ + NeAACDecHandle faac_dec; + NeAACDecConfigurationPtr faac_cfg; + NeAACDecFrameInfo faac_finfo; + int faac_failed; + + int raw_mode; + + unsigned char *buf; + int size; + int rec_audio_src_size; + int max_audio_src_size; + int pts; + + unsigned char *dec_config; + int dec_config_size; + + uint32_t rate; + int bits_per_sample; + unsigned char num_channels; + int sbr; + uint32_t ao_cap_mode; + + int output_open; + + unsigned long total_time; + unsigned long total_data; +} faad_decoder_t; + + +static void faad_reset (audio_decoder_t *this_gen) { + + faad_decoder_t *this = (faad_decoder_t *) this_gen; + this->size = 0; +} + +static void faad_meta_info_set ( faad_decoder_t *this ) { + switch (this->num_channels) { + case 1: + if (this->faac_finfo.sbr == SBR_UPSAMPLED) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "HE-AAC 1.0 (libfaad)"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "AAC 1.0 (libfaad)"); + break; + case 2: + /* check if this is downmixed 5.1 */ + if (!this->faac_cfg || !this->faac_cfg->downMatrix) { + if (this->faac_finfo.sbr == SBR_UPSAMPLED) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "HE-AAC 2.0 (libfaad)"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "AAC 2.0 (libfaad)"); + break; + } + case 6: + if (this->faac_finfo.sbr == SBR_UPSAMPLED) + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "HE-AAC 5.1 (libfaad)"); + else + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "AAC 5.1 (libfaad)"); + break; + } +} + +static int faad_open_dec( faad_decoder_t *this ) { + int used; + + this->faac_dec = NeAACDecOpen(); + if( !this->faac_dec ) { + xprintf( this->stream->xine, XINE_VERBOSITY_LOG, + _("libfaad: libfaad NeAACDecOpen() failed.\n")); + this->faac_failed++; + } else { + if( this->dec_config ) { + used = NeAACDecInit2(this->faac_dec, this->dec_config, this->dec_config_size, + &this->rate, &this->num_channels); + + if( used < 0 ) { + xprintf( this->stream->xine, XINE_VERBOSITY_LOG, + _("libfaad: libfaad NeAACDecInit2 failed.\n")); + this->faac_failed++; + } else + lprintf( "NeAACDecInit2 returned rate=%"PRId32" channels=%d\n", + this->rate, this->num_channels ); + } else { + used = NeAACDecInit(this->faac_dec, this->buf, this->size, + &this->rate, &this->num_channels); + + if( used < 0 ) { + xprintf ( this->stream->xine, XINE_VERBOSITY_LOG, + _("libfaad: libfaad NeAACDecInit failed.\n")); + this->faac_failed++; + } else { + lprintf( "NeAACDecInit() returned rate=%"PRId32" channels=%d (used=%d)\n", + this->rate, this->num_channels, used); + + this->size -= used; + memmove( this->buf, &this->buf[used], this->size ); + } + } + } + + if( !this->bits_per_sample ) + this->bits_per_sample = 16; + + if( this->faac_failed ) { + if( this->faac_dec ) { + NeAACDecClose( this->faac_dec ); + this->faac_dec = NULL; + } + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + } else { + faad_meta_info_set(this); + } + + return this->faac_failed; +} + +static int faad_open_output( faad_decoder_t *this ) { + this->rec_audio_src_size = this->num_channels * FAAD_MIN_STREAMSIZE; + + switch( this->num_channels ) { + case 1: + this->ao_cap_mode=AO_CAP_MODE_MONO; + break; + case 6: + if(this->stream->audio_out->get_capabilities(this->stream->audio_out) & + AO_CAP_MODE_5_1CHANNEL) { + this->ao_cap_mode = AO_CAP_MODE_5_1CHANNEL; + break; + } else { + this->faac_cfg = NeAACDecGetCurrentConfiguration(this->faac_dec); + this->faac_cfg->downMatrix = 1; + NeAACDecSetConfiguration(this->faac_dec, this->faac_cfg); + this->num_channels = 2; + } + case 2: + this->ao_cap_mode=AO_CAP_MODE_STEREO; + break; + } + + this->output_open = this->stream->audio_out->open (this->stream->audio_out, + this->stream, + this->bits_per_sample, + this->rate, + this->ao_cap_mode) ; + return this->output_open; +} + +static void faad_decode_audio ( faad_decoder_t *this, int end_frame ) { + int used, decoded, outsize; + uint8_t *sample_buffer; + uint8_t *inbuf; + audio_buffer_t *audio_buffer; + int sample_size = this->size; + + if( !this->faac_dec ) + return; + + inbuf = this->buf; + while( (!this->raw_mode && end_frame && this->size >= 10) || + (this->raw_mode && this->size >= this->rec_audio_src_size) ) { + + sample_buffer = NeAACDecDecode(this->faac_dec, + &this->faac_finfo, inbuf, sample_size); + + if( !sample_buffer ) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "libfaad: %s\n", NeAACDecGetErrorMessage(this->faac_finfo.error)); + used = 1; + } else { + used = this->faac_finfo.bytesconsumed; + + /* raw AAC parameters might only be known after decoding the first frame */ + if( !this->dec_config && + (this->num_channels != this->faac_finfo.channels || + this->rate != this->faac_finfo.samplerate) ) { + + this->num_channels = this->faac_finfo.channels; + this->rate = this->faac_finfo.samplerate; + + lprintf("faacDecDecode() returned rate=%"PRId32" channels=%d used=%d\n", + this->rate, this->num_channels, used); + + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + faad_open_output( this ); + + faad_meta_info_set( this ); + } + + /* faad doesn't tell us about sbr until after the first frame */ + if (this->sbr != this->faac_finfo.sbr) { + this->sbr = this->faac_finfo.sbr; + faad_meta_info_set( this ); + } + + /* estimate bitrate */ + this->total_time += (1000*this->faac_finfo.samples/(this->rate*this->num_channels)); + this->total_data += 8*used; + + if ((this->total_time > LONG_MAX) || (this->total_data > LONG_MAX)) { + this->total_time >>= 2; + this->total_data >>= 2; + } + + if (this->total_time) + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, + 1000*(this->total_data/this->total_time)); + + decoded = this->faac_finfo.samples * 2; /* 1 sample = 2 bytes */ + + lprintf("decoded %d/%d output %ld\n", + used, this->size, this->faac_finfo.samples ); + + while( decoded ) { + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + + if( decoded < audio_buffer->mem_size ) + outsize = decoded; + else + outsize = audio_buffer->mem_size; + + xine_fast_memcpy( audio_buffer->mem, sample_buffer, outsize ); + + audio_buffer->num_frames = outsize / (this->num_channels*2); + audio_buffer->vpts = this->pts; + + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + + this->pts = 0; + decoded -= outsize; + sample_buffer += outsize; + } + } + + if(used >= this->size){ + this->size = 0; + } else { + this->size -= used; + inbuf += used; + } + + if( !this->raw_mode ) + this->size = 0; + } + + if( this->size ) + memmove( this->buf, inbuf, this->size); + +} + +static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + faad_decoder_t *this = (faad_decoder_t *) this_gen; + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + /* store config information from ESDS mp4/qt atom */ + if( !this->faac_dec && (buf->decoder_flags & BUF_FLAG_SPECIAL) && + buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG ) { + + this->dec_config = xine_xmalloc(buf->decoder_info[2]); + this->dec_config_size = buf->decoder_info[2]; + memcpy(this->dec_config, buf->decoder_info_ptr[2], buf->decoder_info[2]); + + if( faad_open_dec(this) ) + return; + + this->raw_mode = 0; + } + + /* get audio parameters from file header + (may be overwritten by libfaad returned parameters) */ + if (buf->decoder_flags & BUF_FLAG_STDHEADER) { + this->rate=buf->decoder_info[1]; + this->bits_per_sample=buf->decoder_info[2] ; + this->num_channels=buf->decoder_info[3] ; + + if( buf->size > sizeof(xine_waveformatex) ) { + xine_waveformatex *wavex = (xine_waveformatex *) buf->content; + + if( wavex->cbSize > 0 ) { + this->dec_config = xine_xmalloc(wavex->cbSize); + this->dec_config_size = wavex->cbSize; + memcpy(this->dec_config, buf->content + sizeof(xine_waveformatex), + wavex->cbSize); + + if( faad_open_dec(this) ) + return; + + this->raw_mode = 0; + } + } + } else { + + lprintf ("decoding %d data bytes...\n", buf->size); + + if( (int)buf->size <= 0 || this->faac_failed ) + return; + + if( !this->size ) + this->pts = buf->pts; + + if( this->size + buf->size > this->max_audio_src_size ) { + this->max_audio_src_size = this->size + 2 * buf->size; + this->buf = realloc( this->buf, this->max_audio_src_size ); + } + + memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if( !this->faac_dec && faad_open_dec(this) ) + return; + + /* open audio device as needed */ + if (!this->output_open) { + faad_open_output( this ); + } + + faad_decode_audio(this, buf->decoder_flags & BUF_FLAG_FRAME_END ); + } +} + +static void faad_discontinuity (audio_decoder_t *this_gen) { +} + +static void faad_dispose (audio_decoder_t *this_gen) { + + faad_decoder_t *this = (faad_decoder_t *) this_gen; + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + if( this->buf ) + free(this->buf); + this->buf = NULL; + this->size = 0; + this->max_audio_src_size = 0; + + if( this->dec_config ) + free(this->dec_config); + this->dec_config = NULL; + this->dec_config_size = 0; + + if( this->faac_dec ) + NeAACDecClose(this->faac_dec); + this->faac_dec = NULL; + this->faac_failed = 0; + + free (this); +} + + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + faad_decoder_t *this ; + + this = (faad_decoder_t *) xine_xmalloc (sizeof (faad_decoder_t)); + + this->audio_decoder.decode_data = faad_decode_data; + this->audio_decoder.reset = faad_reset; + this->audio_decoder.discontinuity = faad_discontinuity; + this->audio_decoder.dispose = faad_dispose; + + this->stream = stream; + this->output_open = 0; + this->raw_mode = 1; + this->faac_dec = NULL; + this->faac_failed = 0; + this->buf = NULL; + this->size = 0; + this->max_audio_src_size = 0; + this->dec_config = NULL; + this->dec_config_size = 0; + this->total_time = 0; + this->total_data = 0; + + this->rate = 0; + + return &this->audio_decoder; +} + +static char *get_identifier (audio_decoder_class_t *this) { + return "FAAD"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "Freeware Advanced Audio Decoder"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + faad_class_t *this ; + + this = (faad_class_t *) xine_xmalloc (sizeof (faad_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_AAC, 0 + }; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "faad", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From 0045b338e45e2c23b0ec6c086e7cb289517831e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 21:21:26 +0200 Subject: Convert to xineplug_LTLIBRARIES. --- src/libxineadec/Makefile.am | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libxineadec/Makefile.am b/src/libxineadec/Makefile.am index 7f34b4bfd..82011dfd0 100644 --- a/src/libxineadec/Makefile.am +++ b/src/libxineadec/Makefile.am @@ -2,24 +2,22 @@ include $(top_srcdir)/misc/Makefile.common EXTRA_DIST = fooaudio.c -libdir = $(XINE_PLUGINDIR) - SUBDIRS = gsm610 nosefart -lib_LTLIBRARIES = \ +xineplug_LTLIBRARIES = \ xineplug_decode_gsm610.la \ xineplug_decode_nsf.la xineplug_decode_gsm610_la_SOURCES = gsm610.c xineplug_decode_gsm610_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_gsm610_la_LDFLAGS = -avoid-version -module +xineplug_decode_gsm610_la_LDFLAGS = $(xineplug_ldflags) xineplug_decode_gsm610_la_LIBADD = \ $(XINE_LIB) \ $(top_builddir)/src/libxineadec/gsm610/libgsm610.la xineplug_decode_nsf_la_SOURCES = nsf.c xineplug_decode_nsf_la_CFLAGS = $(VISIBILITY_FLAG) -DNSF_PLAYER -fno-strict-aliasing -xineplug_decode_nsf_la_LDFLAGS = -avoid-version -module +xineplug_decode_nsf_la_LDFLAGS = $(xineplug_ldflags) xineplug_decode_nsf_la_LIBADD = -lm \ $(XINE_LIB) \ $(top_builddir)/src/libxineadec/nosefart/libnosefart.la -- cgit v1.2.3 From 54999f68a60f0f814566babb2df0f9a18089d149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:00:36 +0200 Subject: Move the linear pcm decoder from liblpcm to libxineadec, as it's a single file. --HG-- rename : src/liblpcm/xine_decoder.c => src/libxineadec/xine_lpcm_decoder.c --- src/Makefile.am | 1 - src/liblpcm/Makefile.am | 10 -- src/liblpcm/xine_decoder.c | 288 ------------------------------------ src/libxineadec/Makefile.am | 19 ++- src/libxineadec/xine_lpcm_decoder.c | 288 ++++++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+), 309 deletions(-) delete mode 100644 src/liblpcm/Makefile.am delete mode 100644 src/liblpcm/xine_decoder.c create mode 100644 src/libxineadec/xine_lpcm_decoder.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index df8e2d462..90f51ee50 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,7 +20,6 @@ SUBDIRS = \ libdts \ libmad \ libw32dll \ - liblpcm \ libxinevdec \ libxineadec \ libvorbis \ diff --git a/src/liblpcm/Makefile.am b/src/liblpcm/Makefile.am deleted file mode 100644 index e8527ee5c..000000000 --- a/src/liblpcm/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_lpcm.la - -xineplug_decode_lpcm_la_SOURCES = xine_decoder.c -xineplug_decode_lpcm_la_LIBADD = $(XINE_LIB) -xineplug_decode_lpcm_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_lpcm_la_LDFLAGS = -avoid-version -module diff --git a/src/liblpcm/xine_decoder.c b/src/liblpcm/xine_decoder.c deleted file mode 100644 index 43bea4cbf..000000000 --- a/src/liblpcm/xine_decoder.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.62 2007/03/17 20:59:36 dgp85 Exp $ - * - * 31-8-2001 Added LPCM rate sensing. - * (c) 2001 James Courtier-Dutton James@superbug.demon.co.uk - * - */ -#ifndef __sun -#define _XOPEN_SOURCE 500 -#endif -/* avoid compiler warnings */ -#define _BSD_SOURCE 1 - -#include -#include -#include -#include -#include -#include -#include /* ntohs */ - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" - -#ifdef WIN32 -#include -/*#include */ /* htons */ -#endif - -typedef struct { - audio_decoder_class_t decoder_class; -} lpcm_class_t; - -typedef struct lpcm_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - uint32_t rate; - uint32_t bits_per_sample; - uint32_t number_of_channels; - uint32_t ao_cap_mode; - - int output_open; - int cpu_be; /* TRUE, if we're a Big endian CPU */ -} lpcm_decoder_t; - -static void lpcm_reset (audio_decoder_t *this_gen) { - - /* lpcm_decoder_t *this = (lpcm_decoder_t *) this_gen; */ - -} - -static void lpcm_discontinuity (audio_decoder_t *this_gen) { -} - -static void lpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - lpcm_decoder_t *this = (lpcm_decoder_t *) this_gen; - int16_t *sample_buffer=(int16_t *)buf->content; - int stream_be; - audio_buffer_t *audio_buffer; - int format_changed = 0; - - /* Drop preview data */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* get config byte from mpeg2 stream */ - if ( (buf->decoder_flags & BUF_FLAG_SPECIAL) && - buf->decoder_info[1] == BUF_SPECIAL_LPCM_CONFIG ) { - unsigned int bits_per_sample = 16; - unsigned int sample_rate = 0; - unsigned int num_channels; - - num_channels = (buf->decoder_info[2] & 0x7) + 1; - switch ((buf->decoder_info[2]>>4) & 3) { - case 0: sample_rate = 48000; break; - case 1: sample_rate = 96000; break; - case 2: sample_rate = 44100; break; - case 3: sample_rate = 32000; break; - } - switch ((buf->decoder_info[2]>>6) & 3) { - case 0: bits_per_sample = 16; break; - case 1: bits_per_sample = 20; break; - case 2: bits_per_sample = 24; break; - } - - if( this->bits_per_sample != bits_per_sample || - this->number_of_channels != num_channels || - this->rate != sample_rate || - !this->output_open ) { - this->bits_per_sample = bits_per_sample; - this->number_of_channels = num_channels; - this->rate = sample_rate; - format_changed++; - } - } - - if( buf->decoder_flags & BUF_FLAG_STDHEADER ) { - this->rate=buf->decoder_info[1]; - this->bits_per_sample=buf->decoder_info[2] ; - this->number_of_channels=buf->decoder_info[3] ; - format_changed++; - } - - /* - * (re-)open output device - */ - if ( format_changed ) { - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - this->ao_cap_mode=_x_ao_channels2mode(this->number_of_channels); - - /* force 24-bit samples into 16 bits for now */ - if (this->bits_per_sample == 24) - this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream, - 16, - this->rate, - this->ao_cap_mode) ; - else - this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream, - this->bits_per_sample, - this->rate, - this->ao_cap_mode) ; - - /* stream/meta info */ - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Linear PCM"); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, - this->bits_per_sample * this->rate * this->number_of_channels); - } - - if (!this->output_open || (buf->decoder_flags & BUF_FLAG_HEADER) ) - return; - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - /* Swap LPCM samples into native byte order, if necessary */ - buf->type &= 0xffff0000; - stream_be = ( buf->type == BUF_AUDIO_LPCM_BE ); - - if( this->bits_per_sample == 16 ){ - if (stream_be != this->cpu_be) - swab (sample_buffer, audio_buffer->mem, buf->size); - else - memcpy (audio_buffer->mem, sample_buffer, buf->size); - } - else if( this->bits_per_sample == 20 ) { - uint8_t *s = (uint8_t *)sample_buffer; - uint8_t *d = (uint8_t *)audio_buffer->mem; - int n = buf->size; - - if (stream_be != this->cpu_be) { - while( n >= 0 ) { - swab( s, d, 8 ); - s += 10; - d += 8; - n -= 10; - } - } else { - while( n >= 0 ) { - memcpy( d, s, 8 ); - s += 10; - d += 8; - n -= 10; - } - } - } else if( this->bits_per_sample == 24 ) { - uint8_t *s = (uint8_t *)sample_buffer; - uint8_t *d = (uint8_t *)audio_buffer->mem; - int n = buf->size; - - while (n >= 0) { - if ( stream_be ) { - *d++ = s[0]; - *d++ = s[1]; - } else { - *d++ = s[1]; - *d++ = s[2]; - } - - s += 3; - n -= 3; - } - } else { - memcpy (audio_buffer->mem, sample_buffer, buf->size); - } - - audio_buffer->vpts = buf->pts; - audio_buffer->num_frames = (((buf->size*8)/this->number_of_channels)/this->bits_per_sample); - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - -} - -static void lpcm_dispose (audio_decoder_t *this_gen) { - lpcm_decoder_t *this = (lpcm_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - lpcm_decoder_t *this ; - - this = (lpcm_decoder_t *) xine_xmalloc (sizeof (lpcm_decoder_t)); - - this->audio_decoder.decode_data = lpcm_decode_data; - this->audio_decoder.reset = lpcm_reset; - this->audio_decoder.discontinuity = lpcm_discontinuity; - this->audio_decoder.dispose = lpcm_dispose; - - this->output_open = 0; - this->rate = 0; - this->bits_per_sample=0; - this->number_of_channels=0; - this->ao_cap_mode=0; - this->stream = stream; - - this->cpu_be = ( htons(1) == 1 ); - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "Linear PCM"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "Linear PCM audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - lpcm_class_t *this ; - - this = (lpcm_class_t *) xine_xmalloc (sizeof (lpcm_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_LPCM_BE, BUF_AUDIO_LPCM_LE, 0 -}; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "pcm", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxineadec/Makefile.am b/src/libxineadec/Makefile.am index 82011dfd0..373347aaa 100644 --- a/src/libxineadec/Makefile.am +++ b/src/libxineadec/Makefile.am @@ -4,22 +4,21 @@ EXTRA_DIST = fooaudio.c SUBDIRS = gsm610 nosefart +AM_LDFLAGS = $(xineplug_ldflags) + xineplug_LTLIBRARIES = \ xineplug_decode_gsm610.la \ - xineplug_decode_nsf.la + xineplug_decode_nsf.la \ + xineplug_decode_lpcm.la xineplug_decode_gsm610_la_SOURCES = gsm610.c xineplug_decode_gsm610_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_gsm610_la_LDFLAGS = $(xineplug_ldflags) -xineplug_decode_gsm610_la_LIBADD = \ - $(XINE_LIB) \ - $(top_builddir)/src/libxineadec/gsm610/libgsm610.la +xineplug_decode_gsm610_la_LIBADD = $(XINE_LIB) gsm610/libgsm610.la xineplug_decode_nsf_la_SOURCES = nsf.c xineplug_decode_nsf_la_CFLAGS = $(VISIBILITY_FLAG) -DNSF_PLAYER -fno-strict-aliasing -xineplug_decode_nsf_la_LDFLAGS = $(xineplug_ldflags) -xineplug_decode_nsf_la_LIBADD = -lm \ - $(XINE_LIB) \ - $(top_builddir)/src/libxineadec/nosefart/libnosefart.la +xineplug_decode_nsf_la_LIBADD = $(XINE_LIB) -lm nosefart/libnosefart.la -# noinst_HEADERS = +xineplug_decode_lpcm_la_SOURCES = xine_lpcm_decoder.c +xineplug_decode_lpcm_la_CFLAGS = $(VISIBILITY_FLAG) +xineplug_decode_lpcm_la_LIBADD = $(XINE_LIB) diff --git a/src/libxineadec/xine_lpcm_decoder.c b/src/libxineadec/xine_lpcm_decoder.c new file mode 100644 index 000000000..43bea4cbf --- /dev/null +++ b/src/libxineadec/xine_lpcm_decoder.c @@ -0,0 +1,288 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.62 2007/03/17 20:59:36 dgp85 Exp $ + * + * 31-8-2001 Added LPCM rate sensing. + * (c) 2001 James Courtier-Dutton James@superbug.demon.co.uk + * + */ +#ifndef __sun +#define _XOPEN_SOURCE 500 +#endif +/* avoid compiler warnings */ +#define _BSD_SOURCE 1 + +#include +#include +#include +#include +#include +#include +#include /* ntohs */ + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" + +#ifdef WIN32 +#include +/*#include */ /* htons */ +#endif + +typedef struct { + audio_decoder_class_t decoder_class; +} lpcm_class_t; + +typedef struct lpcm_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + uint32_t rate; + uint32_t bits_per_sample; + uint32_t number_of_channels; + uint32_t ao_cap_mode; + + int output_open; + int cpu_be; /* TRUE, if we're a Big endian CPU */ +} lpcm_decoder_t; + +static void lpcm_reset (audio_decoder_t *this_gen) { + + /* lpcm_decoder_t *this = (lpcm_decoder_t *) this_gen; */ + +} + +static void lpcm_discontinuity (audio_decoder_t *this_gen) { +} + +static void lpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + lpcm_decoder_t *this = (lpcm_decoder_t *) this_gen; + int16_t *sample_buffer=(int16_t *)buf->content; + int stream_be; + audio_buffer_t *audio_buffer; + int format_changed = 0; + + /* Drop preview data */ + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + /* get config byte from mpeg2 stream */ + if ( (buf->decoder_flags & BUF_FLAG_SPECIAL) && + buf->decoder_info[1] == BUF_SPECIAL_LPCM_CONFIG ) { + unsigned int bits_per_sample = 16; + unsigned int sample_rate = 0; + unsigned int num_channels; + + num_channels = (buf->decoder_info[2] & 0x7) + 1; + switch ((buf->decoder_info[2]>>4) & 3) { + case 0: sample_rate = 48000; break; + case 1: sample_rate = 96000; break; + case 2: sample_rate = 44100; break; + case 3: sample_rate = 32000; break; + } + switch ((buf->decoder_info[2]>>6) & 3) { + case 0: bits_per_sample = 16; break; + case 1: bits_per_sample = 20; break; + case 2: bits_per_sample = 24; break; + } + + if( this->bits_per_sample != bits_per_sample || + this->number_of_channels != num_channels || + this->rate != sample_rate || + !this->output_open ) { + this->bits_per_sample = bits_per_sample; + this->number_of_channels = num_channels; + this->rate = sample_rate; + format_changed++; + } + } + + if( buf->decoder_flags & BUF_FLAG_STDHEADER ) { + this->rate=buf->decoder_info[1]; + this->bits_per_sample=buf->decoder_info[2] ; + this->number_of_channels=buf->decoder_info[3] ; + format_changed++; + } + + /* + * (re-)open output device + */ + if ( format_changed ) { + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + this->ao_cap_mode=_x_ao_channels2mode(this->number_of_channels); + + /* force 24-bit samples into 16 bits for now */ + if (this->bits_per_sample == 24) + this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream, + 16, + this->rate, + this->ao_cap_mode) ; + else + this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream, + this->bits_per_sample, + this->rate, + this->ao_cap_mode) ; + + /* stream/meta info */ + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Linear PCM"); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, + this->bits_per_sample * this->rate * this->number_of_channels); + } + + if (!this->output_open || (buf->decoder_flags & BUF_FLAG_HEADER) ) + return; + + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + + /* Swap LPCM samples into native byte order, if necessary */ + buf->type &= 0xffff0000; + stream_be = ( buf->type == BUF_AUDIO_LPCM_BE ); + + if( this->bits_per_sample == 16 ){ + if (stream_be != this->cpu_be) + swab (sample_buffer, audio_buffer->mem, buf->size); + else + memcpy (audio_buffer->mem, sample_buffer, buf->size); + } + else if( this->bits_per_sample == 20 ) { + uint8_t *s = (uint8_t *)sample_buffer; + uint8_t *d = (uint8_t *)audio_buffer->mem; + int n = buf->size; + + if (stream_be != this->cpu_be) { + while( n >= 0 ) { + swab( s, d, 8 ); + s += 10; + d += 8; + n -= 10; + } + } else { + while( n >= 0 ) { + memcpy( d, s, 8 ); + s += 10; + d += 8; + n -= 10; + } + } + } else if( this->bits_per_sample == 24 ) { + uint8_t *s = (uint8_t *)sample_buffer; + uint8_t *d = (uint8_t *)audio_buffer->mem; + int n = buf->size; + + while (n >= 0) { + if ( stream_be ) { + *d++ = s[0]; + *d++ = s[1]; + } else { + *d++ = s[1]; + *d++ = s[2]; + } + + s += 3; + n -= 3; + } + } else { + memcpy (audio_buffer->mem, sample_buffer, buf->size); + } + + audio_buffer->vpts = buf->pts; + audio_buffer->num_frames = (((buf->size*8)/this->number_of_channels)/this->bits_per_sample); + + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + +} + +static void lpcm_dispose (audio_decoder_t *this_gen) { + lpcm_decoder_t *this = (lpcm_decoder_t *) this_gen; + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + free (this_gen); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + lpcm_decoder_t *this ; + + this = (lpcm_decoder_t *) xine_xmalloc (sizeof (lpcm_decoder_t)); + + this->audio_decoder.decode_data = lpcm_decode_data; + this->audio_decoder.reset = lpcm_reset; + this->audio_decoder.discontinuity = lpcm_discontinuity; + this->audio_decoder.dispose = lpcm_dispose; + + this->output_open = 0; + this->rate = 0; + this->bits_per_sample=0; + this->number_of_channels=0; + this->ao_cap_mode=0; + this->stream = stream; + + this->cpu_be = ( htons(1) == 1 ); + + return &this->audio_decoder; +} + +static char *get_identifier (audio_decoder_class_t *this) { + return "Linear PCM"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "Linear PCM audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + lpcm_class_t *this ; + + this = (lpcm_class_t *) xine_xmalloc (sizeof (lpcm_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_LPCM_BE, BUF_AUDIO_LPCM_LE, 0 +}; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "pcm", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From 39bf7da5d0ec2e6b6a6b96e97689dd29445b7810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:01:45 +0200 Subject: Rename xine_decoder.c to xine_mad_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libmad/xine_decoder.c => src/libmad/xine_mad_decoder.c --- src/libmad/Makefile.am | 8 +- src/libmad/xine_decoder.c | 375 ------------------------------------------ src/libmad/xine_mad_decoder.c | 375 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 378 insertions(+), 380 deletions(-) delete mode 100644 src/libmad/xine_decoder.c create mode 100644 src/libmad/xine_mad_decoder.c (limited to 'src') diff --git a/src/libmad/Makefile.am b/src/libmad/Makefile.am index 8d704205b..c879645c5 100644 --- a/src/libmad/Makefile.am +++ b/src/libmad/Makefile.am @@ -4,13 +4,11 @@ AM_CFLAGS = -DOPT_SPEED EXTRA_DIST = imdct_l_arm.S -libdir = $(XINE_PLUGINDIR) - if MAD mad_module = xineplug_decode_mad.la endif -lib_LTLIBRARIES = $(mad_module) +xineplug_LTLIBRARIES = $(mad_module) if EXTERNAL_LIBMAD internal_sources = @@ -29,7 +27,7 @@ internal_sources = \ endif xineplug_decode_mad_la_SOURCES = \ - xine_decoder.c \ + xine_mad_decoder.c \ $(internal_sources) if EXTERNAL_LIBMAD @@ -38,7 +36,7 @@ else xineplug_decode_mad_la_LIBADD = $(XINE_LIB) endif xineplug_decode_mad_la_CFLAGS = $(LIBMAD_CFLAGS) $(VISIBILITY_FLAG) -xineplug_decode_mad_la_LDFLAGS = -avoid-version -module +xineplug_decode_mad_la_LDFLAGS = $(xineplug_ldflags) noinst_HEADERS = \ D.dat \ diff --git a/src/libmad/xine_decoder.c b/src/libmad/xine_decoder.c deleted file mode 100644 index 28407cfec..000000000 --- a/src/libmad/xine_decoder.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.57 2006/07/10 22:08:29 dgp85 Exp $ - * - * stuff needed to turn libmad into a xine decoder plugin - */ - -#include -#include -#include - -#ifdef HAVE_MAD_H -#include -#endif - -#define LOG_MODULE "mad_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" -#include "frame.h" -#include "synth.h" -#include "xineutils.h" - -#define INPUT_BUF_SIZE 16384 - -typedef struct { - audio_decoder_class_t decoder_class; -} mad_class_t; - -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; - - int output_sampling_rate; - int output_open; - int output_mode; - - uint8_t buffer[INPUT_BUF_SIZE]; - int bytes_in_buffer; - int preview_mode; - -} mad_decoder_t; - -static void mad_reset (audio_decoder_t *this_gen) { - - mad_decoder_t *this = (mad_decoder_t *) this_gen; - - mad_synth_finish (&this->synth); - mad_frame_finish (&this->frame); - mad_stream_finish(&this->stream); - - this->pts = 0; - this->bytes_in_buffer = 0; - this->preview_mode = 0; - - mad_synth_init (&this->synth); - mad_stream_init (&this->stream); - this->stream.options = MAD_OPTION_IGNORECRC; - mad_frame_init (&this->frame); -} - - -static void mad_discontinuity (audio_decoder_t *this_gen) { - - mad_decoder_t *this = (mad_decoder_t *) this_gen; - - this->pts = 0; -} - -/* utility to scale and round samples to 16 bits */ - -static inline -signed int scale(mad_fixed_t sample) -{ - /* round */ - sample += (1L << (MAD_F_FRACBITS - 16)); - - /* clip */ - if (sample >= MAD_F_ONE) - sample = MAD_F_ONE - 1; - else if (sample < -MAD_F_ONE) - sample = -MAD_F_ONE; - - /* quantize */ - return sample >> (MAD_F_FRACBITS + 1 - 16); -} - -/* -static int head_check(mad_decoder_t *this) { - - if( (this->header & 0xffe00000) != 0xffe00000) - return 0; - if(!((this->header>>17)&3)) - return 0; - if( ((this->header>>12)&0xf) == 0xf) - return 0; - if( ((this->header>>10)&0x3) == 0x3 ) - return 0; - return 1; -} -*/ - -static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - mad_decoder_t *this = (mad_decoder_t *) this_gen; - - lprintf ("decode data, decoder_flags: %d\n", buf->decoder_flags); - - if (buf->size>(INPUT_BUF_SIZE-this->bytes_in_buffer)) { - xprintf (this->xstream->xine, XINE_VERBOSITY_DEBUG, - "libmad: ALERT input buffer too small (%d bytes, %d avail)!\n", - buf->size, INPUT_BUF_SIZE-this->bytes_in_buffer); - buf->size = INPUT_BUF_SIZE-this->bytes_in_buffer; - } - - if ((buf->decoder_flags & BUF_FLAG_HEADER) == 0) { - - /* reset decoder on leaving preview mode */ - if ((buf->decoder_flags & BUF_FLAG_PREVIEW) == 0) { - if (this->preview_mode) { - mad_reset (this_gen); - } - } else { - this->preview_mode = 1; - } - - xine_fast_memcpy (&this->buffer[this->bytes_in_buffer], - buf->content, buf->size); - this->bytes_in_buffer += buf->size; - - /* - printf ("libmad: decode data - doing it\n"); - */ - - mad_stream_buffer (&this->stream, this->buffer, - this->bytes_in_buffer); - - while (1) { - - if (mad_frame_decode (&this->frame, &this->stream) != 0) { - - if (this->stream.next_frame) { - int num_bytes = - this->buffer + this->bytes_in_buffer - this->stream.next_frame; - - /* printf("libmad: MAD_ERROR_BUFLEN\n"); */ - - memmove(this->buffer, this->stream.next_frame, num_bytes); - this->bytes_in_buffer = num_bytes; - } - - switch (this->stream.error) { - - case MAD_ERROR_BUFLEN: - return; - - default: - mad_stream_buffer (&this->stream, this->buffer, - this->bytes_in_buffer); - } - - } else { - int mode = (this->frame.header.mode == MAD_MODE_SINGLE_CHANNEL) ? AO_CAP_MODE_MONO : AO_CAP_MODE_STEREO; - - if (!this->output_open - || (this->output_sampling_rate != this->frame.header.samplerate) - || (this->output_mode != mode)) { - - lprintf ("audio sample rate %d mode %08x\n", this->frame.header.samplerate, mode); - - /* the mpeg audio demuxer can set audio bitrate */ - if (! _x_stream_info_get(this->xstream, XINE_STREAM_INFO_AUDIO_BITRATE)) { - _x_stream_info_set(this->xstream, XINE_STREAM_INFO_AUDIO_BITRATE, - this->frame.header.bitrate); - } - - /* the mpeg audio demuxer can set this meta info */ - if (! _x_meta_info_get(this->xstream, XINE_META_INFO_AUDIOCODEC)) { - switch (this->frame.header.layer) { - case MAD_LAYER_I: - _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, - "MPEG audio layer 1 (lib: MAD)"); - break; - case MAD_LAYER_II: - _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, - "MPEG audio layer 2 (lib: MAD)"); - break; - case MAD_LAYER_III: - _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, - "MPEG audio layer 3 (lib: MAD)"); - break; - default: - _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, - "MPEG audio (lib: MAD)"); - } - } - - if (this->output_open) { - this->xstream->audio_out->close (this->xstream->audio_out, this->xstream); - this->output_open = 0; - } - if (!this->output_open) { - this->output_open = this->xstream->audio_out->open(this->xstream->audio_out, - this->xstream, 16, - this->frame.header.samplerate, - mode) ; - } - if (!this->output_open) { - return; - } - this->output_sampling_rate = this->frame.header.samplerate; - this->output_mode = mode; - } - - mad_synth_frame (&this->synth, &this->frame); - - if ( (buf->decoder_flags & BUF_FLAG_PREVIEW) == 0 ) { - - unsigned int nchannels, nsamples; - mad_fixed_t const *left_ch, *right_ch; - struct mad_pcm *pcm = &this->synth.pcm; - audio_buffer_t *audio_buffer; - uint16_t *output; - - audio_buffer = this->xstream->audio_out->get_buffer (this->xstream->audio_out); - output = audio_buffer->mem; - - nchannels = pcm->channels; - nsamples = pcm->length; - left_ch = pcm->samples[0]; - right_ch = pcm->samples[1]; - - while (nsamples--) { - /* output sample(s) in 16-bit signed little-endian PCM */ - - *output++ = scale(*left_ch++); - - if (nchannels == 2) - *output++ = scale(*right_ch++); - - } - - audio_buffer->num_frames = pcm->length; - audio_buffer->vpts = buf->pts; - - this->xstream->audio_out->put_buffer (this->xstream->audio_out, audio_buffer, this->xstream); - - buf->pts = 0; - - } - - lprintf ("decode worked\n"); - } - } - - } -} - -static void mad_dispose (audio_decoder_t *this_gen) { - - mad_decoder_t *this = (mad_decoder_t *) this_gen; - - mad_synth_finish (&this->synth); - mad_frame_finish (&this->frame); - mad_stream_finish(&this->stream); - - if (this->output_open) { - this->xstream->audio_out->close (this->xstream->audio_out, this->xstream); - this->output_open = 0; - } - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - mad_decoder_t *this ; - - this = (mad_decoder_t *) xine_xmalloc (sizeof (mad_decoder_t)); - - this->audio_decoder.decode_data = mad_decode_data; - this->audio_decoder.reset = mad_reset; - this->audio_decoder.discontinuity = mad_discontinuity; - this->audio_decoder.dispose = mad_dispose; - - this->output_open = 0; - this->bytes_in_buffer = 0; - this->preview_mode = 0; - - this->xstream = stream; - - mad_synth_init (&this->synth); - mad_stream_init (&this->stream); - mad_frame_init (&this->frame); - - this->stream.options = MAD_OPTION_IGNORECRC; - - lprintf ("init\n"); - - return &this->audio_decoder; -} - -/* - * mad plugin class - */ - -static char *get_identifier (audio_decoder_class_t *this) { - return "mad"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "libmad based mpeg audio layer 1/2/3 decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - mad_class_t *this; - - this = (mad_class_t *) xine_xmalloc (sizeof (mad_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_MPEG, 0 -}; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 7 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "mad", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libmad/xine_mad_decoder.c b/src/libmad/xine_mad_decoder.c new file mode 100644 index 000000000..28407cfec --- /dev/null +++ b/src/libmad/xine_mad_decoder.c @@ -0,0 +1,375 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.57 2006/07/10 22:08:29 dgp85 Exp $ + * + * stuff needed to turn libmad into a xine decoder plugin + */ + +#include +#include +#include + +#ifdef HAVE_MAD_H +#include +#endif + +#define LOG_MODULE "mad_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" +#include "frame.h" +#include "synth.h" +#include "xineutils.h" + +#define INPUT_BUF_SIZE 16384 + +typedef struct { + audio_decoder_class_t decoder_class; +} mad_class_t; + +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; + + int output_sampling_rate; + int output_open; + int output_mode; + + uint8_t buffer[INPUT_BUF_SIZE]; + int bytes_in_buffer; + int preview_mode; + +} mad_decoder_t; + +static void mad_reset (audio_decoder_t *this_gen) { + + mad_decoder_t *this = (mad_decoder_t *) this_gen; + + mad_synth_finish (&this->synth); + mad_frame_finish (&this->frame); + mad_stream_finish(&this->stream); + + this->pts = 0; + this->bytes_in_buffer = 0; + this->preview_mode = 0; + + mad_synth_init (&this->synth); + mad_stream_init (&this->stream); + this->stream.options = MAD_OPTION_IGNORECRC; + mad_frame_init (&this->frame); +} + + +static void mad_discontinuity (audio_decoder_t *this_gen) { + + mad_decoder_t *this = (mad_decoder_t *) this_gen; + + this->pts = 0; +} + +/* utility to scale and round samples to 16 bits */ + +static inline +signed int scale(mad_fixed_t sample) +{ + /* round */ + sample += (1L << (MAD_F_FRACBITS - 16)); + + /* clip */ + if (sample >= MAD_F_ONE) + sample = MAD_F_ONE - 1; + else if (sample < -MAD_F_ONE) + sample = -MAD_F_ONE; + + /* quantize */ + return sample >> (MAD_F_FRACBITS + 1 - 16); +} + +/* +static int head_check(mad_decoder_t *this) { + + if( (this->header & 0xffe00000) != 0xffe00000) + return 0; + if(!((this->header>>17)&3)) + return 0; + if( ((this->header>>12)&0xf) == 0xf) + return 0; + if( ((this->header>>10)&0x3) == 0x3 ) + return 0; + return 1; +} +*/ + +static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + mad_decoder_t *this = (mad_decoder_t *) this_gen; + + lprintf ("decode data, decoder_flags: %d\n", buf->decoder_flags); + + if (buf->size>(INPUT_BUF_SIZE-this->bytes_in_buffer)) { + xprintf (this->xstream->xine, XINE_VERBOSITY_DEBUG, + "libmad: ALERT input buffer too small (%d bytes, %d avail)!\n", + buf->size, INPUT_BUF_SIZE-this->bytes_in_buffer); + buf->size = INPUT_BUF_SIZE-this->bytes_in_buffer; + } + + if ((buf->decoder_flags & BUF_FLAG_HEADER) == 0) { + + /* reset decoder on leaving preview mode */ + if ((buf->decoder_flags & BUF_FLAG_PREVIEW) == 0) { + if (this->preview_mode) { + mad_reset (this_gen); + } + } else { + this->preview_mode = 1; + } + + xine_fast_memcpy (&this->buffer[this->bytes_in_buffer], + buf->content, buf->size); + this->bytes_in_buffer += buf->size; + + /* + printf ("libmad: decode data - doing it\n"); + */ + + mad_stream_buffer (&this->stream, this->buffer, + this->bytes_in_buffer); + + while (1) { + + if (mad_frame_decode (&this->frame, &this->stream) != 0) { + + if (this->stream.next_frame) { + int num_bytes = + this->buffer + this->bytes_in_buffer - this->stream.next_frame; + + /* printf("libmad: MAD_ERROR_BUFLEN\n"); */ + + memmove(this->buffer, this->stream.next_frame, num_bytes); + this->bytes_in_buffer = num_bytes; + } + + switch (this->stream.error) { + + case MAD_ERROR_BUFLEN: + return; + + default: + mad_stream_buffer (&this->stream, this->buffer, + this->bytes_in_buffer); + } + + } else { + int mode = (this->frame.header.mode == MAD_MODE_SINGLE_CHANNEL) ? AO_CAP_MODE_MONO : AO_CAP_MODE_STEREO; + + if (!this->output_open + || (this->output_sampling_rate != this->frame.header.samplerate) + || (this->output_mode != mode)) { + + lprintf ("audio sample rate %d mode %08x\n", this->frame.header.samplerate, mode); + + /* the mpeg audio demuxer can set audio bitrate */ + if (! _x_stream_info_get(this->xstream, XINE_STREAM_INFO_AUDIO_BITRATE)) { + _x_stream_info_set(this->xstream, XINE_STREAM_INFO_AUDIO_BITRATE, + this->frame.header.bitrate); + } + + /* the mpeg audio demuxer can set this meta info */ + if (! _x_meta_info_get(this->xstream, XINE_META_INFO_AUDIOCODEC)) { + switch (this->frame.header.layer) { + case MAD_LAYER_I: + _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, + "MPEG audio layer 1 (lib: MAD)"); + break; + case MAD_LAYER_II: + _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, + "MPEG audio layer 2 (lib: MAD)"); + break; + case MAD_LAYER_III: + _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, + "MPEG audio layer 3 (lib: MAD)"); + break; + default: + _x_meta_info_set_utf8(this->xstream, XINE_META_INFO_AUDIOCODEC, + "MPEG audio (lib: MAD)"); + } + } + + if (this->output_open) { + this->xstream->audio_out->close (this->xstream->audio_out, this->xstream); + this->output_open = 0; + } + if (!this->output_open) { + this->output_open = this->xstream->audio_out->open(this->xstream->audio_out, + this->xstream, 16, + this->frame.header.samplerate, + mode) ; + } + if (!this->output_open) { + return; + } + this->output_sampling_rate = this->frame.header.samplerate; + this->output_mode = mode; + } + + mad_synth_frame (&this->synth, &this->frame); + + if ( (buf->decoder_flags & BUF_FLAG_PREVIEW) == 0 ) { + + unsigned int nchannels, nsamples; + mad_fixed_t const *left_ch, *right_ch; + struct mad_pcm *pcm = &this->synth.pcm; + audio_buffer_t *audio_buffer; + uint16_t *output; + + audio_buffer = this->xstream->audio_out->get_buffer (this->xstream->audio_out); + output = audio_buffer->mem; + + nchannels = pcm->channels; + nsamples = pcm->length; + left_ch = pcm->samples[0]; + right_ch = pcm->samples[1]; + + while (nsamples--) { + /* output sample(s) in 16-bit signed little-endian PCM */ + + *output++ = scale(*left_ch++); + + if (nchannels == 2) + *output++ = scale(*right_ch++); + + } + + audio_buffer->num_frames = pcm->length; + audio_buffer->vpts = buf->pts; + + this->xstream->audio_out->put_buffer (this->xstream->audio_out, audio_buffer, this->xstream); + + buf->pts = 0; + + } + + lprintf ("decode worked\n"); + } + } + + } +} + +static void mad_dispose (audio_decoder_t *this_gen) { + + mad_decoder_t *this = (mad_decoder_t *) this_gen; + + mad_synth_finish (&this->synth); + mad_frame_finish (&this->frame); + mad_stream_finish(&this->stream); + + if (this->output_open) { + this->xstream->audio_out->close (this->xstream->audio_out, this->xstream); + this->output_open = 0; + } + + free (this_gen); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + mad_decoder_t *this ; + + this = (mad_decoder_t *) xine_xmalloc (sizeof (mad_decoder_t)); + + this->audio_decoder.decode_data = mad_decode_data; + this->audio_decoder.reset = mad_reset; + this->audio_decoder.discontinuity = mad_discontinuity; + this->audio_decoder.dispose = mad_dispose; + + this->output_open = 0; + this->bytes_in_buffer = 0; + this->preview_mode = 0; + + this->xstream = stream; + + mad_synth_init (&this->synth); + mad_stream_init (&this->stream); + mad_frame_init (&this->frame); + + this->stream.options = MAD_OPTION_IGNORECRC; + + lprintf ("init\n"); + + return &this->audio_decoder; +} + +/* + * mad plugin class + */ + +static char *get_identifier (audio_decoder_class_t *this) { + return "mad"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "libmad based mpeg audio layer 1/2/3 decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + mad_class_t *this; + + this = (mad_class_t *) xine_xmalloc (sizeof (mad_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_MPEG, 0 +}; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 7 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "mad", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From cbcc2cc3c185b5799f34a7918b44b743a70decab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:05:54 +0200 Subject: Move the Vorbis decoder from libvorbis to libxineadec, as it's a single file. --HG-- rename : src/libvorbis/xine_decoder.c => src/libxineadec/xine_vorbis_decoder.c --- src/Makefile.am | 1 - src/libvorbis/Makefile.am | 14 -- src/libvorbis/xine_decoder.c | 354 ---------------------------------- src/libxineadec/Makefile.am | 11 +- src/libxineadec/xine_vorbis_decoder.c | 354 ++++++++++++++++++++++++++++++++++ 5 files changed, 364 insertions(+), 370 deletions(-) delete mode 100644 src/libvorbis/Makefile.am delete mode 100644 src/libvorbis/xine_decoder.c create mode 100644 src/libxineadec/xine_vorbis_decoder.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 90f51ee50..86832bf18 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,6 @@ SUBDIRS = \ libw32dll \ libxinevdec \ libxineadec \ - libvorbis \ libtheora \ libspeex \ libreal \ diff --git a/src/libvorbis/Makefile.am b/src/libvorbis/Makefile.am deleted file mode 100644 index 09abced93..000000000 --- a/src/libvorbis/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -libdir = $(XINE_PLUGINDIR) - -if HAVE_VORBIS -vorbis_module = xineplug_decode_vorbis.la -endif - -lib_LTLIBRARIES = $(vorbis_module) - -xineplug_decode_vorbis_la_SOURCES = xine_decoder.c -xineplug_decode_vorbis_la_LIBADD = $(VORBIS_LIBS) $(OGG_LIBS) $(XINE_LIB) -xineplug_decode_vorbis_la_CFLAGS = $(VORBIS_CFLAGS) $(VISIBILITY_FLAG) -xineplug_decode_vorbis_la_LDFLAGS = -avoid-version -module diff --git a/src/libvorbis/xine_decoder.c b/src/libvorbis/xine_decoder.c deleted file mode 100644 index ef8575949..000000000 --- a/src/libvorbis/xine_decoder.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.48 2006/12/04 13:59:38 dgp85 Exp $ - * - * (ogg/)vorbis audio decoder plugin (libvorbis wrapper) for xine - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#define LOG_MODULE "vorbis_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" - -#include -#include - -#define MAX_NUM_SAMPLES 4096 - -typedef struct { - audio_decoder_class_t decoder_class; -} vorbis_class_t; - -typedef struct vorbis_decoder_s { - audio_decoder_t audio_decoder; - - int64_t pts; - - int output_sampling_rate; - int output_open; - int output_mode; - - ogg_packet op; /* we must use this struct to sent data to libvorbis */ - - /* vorbis stuff */ - vorbis_info vi; /* stores static vorbis bitstream settings */ - vorbis_comment vc; - vorbis_dsp_state vd; /* central working state for packet->PCM decoder */ - vorbis_block vb; /* local working state for packet->PCM decoder */ - - int16_t convbuffer[MAX_NUM_SAMPLES]; - int convsize; - - int header_count; - - xine_stream_t *stream; - -} vorbis_decoder_t; - - -static void vorbis_reset (audio_decoder_t *this_gen) { - - vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; - - if( !this->header_count ) - vorbis_block_init(&this->vd,&this->vb); -} - -static void vorbis_discontinuity (audio_decoder_t *this_gen) { - - vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; - - this->pts=0; -} - -/* Known vorbis comment keys from ogg123 sources*/ -static struct { - char *key; /* includes the '=' for programming convenience */ - int xine_metainfo_index; -} vorbis_comment_keys[] = { - {"ARTIST=", XINE_META_INFO_ARTIST}, - {"ALBUM=", XINE_META_INFO_ALBUM}, - {"TITLE=", XINE_META_INFO_TITLE}, - {"GENRE=", XINE_META_INFO_GENRE}, - {"DESCRIPTION=", XINE_META_INFO_COMMENT}, - {"COMMENT=", XINE_META_INFO_COMMENT}, - {"DATE=", XINE_META_INFO_YEAR}, - {"TRACKNUMBER=", XINE_META_INFO_TRACK_NUMBER}, - {NULL, 0} -}; - -static void get_metadata (vorbis_decoder_t *this) { - - char **ptr=this->vc.user_comments; - while(*ptr){ - - char *comment = *ptr; - int i; - - lprintf("%s\n", comment); - - for (i = 0; vorbis_comment_keys[i].key != NULL; i++) { - - if ( !strncasecmp (vorbis_comment_keys[i].key, comment, - strlen(vorbis_comment_keys[i].key)) ) { - - lprintf ("known metadata %d %d\n", - i, vorbis_comment_keys[i].xine_metainfo_index); - - _x_meta_info_set_utf8(this->stream, vorbis_comment_keys[i].xine_metainfo_index, - comment + strlen(vorbis_comment_keys[i].key)); - - } - } - ++ptr; - } - - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "vorbis"); -} - -static void vorbis_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; - - memset( &this->op, 0, sizeof(this->op) ); - this->op.packet = buf->content; - this->op.bytes = buf->size; - - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { - lprintf ("%d headers to go\n", this->header_count); - - if (this->header_count) { - int res = 0; - - if (this->header_count == 3) - this->op.b_o_s = 1; - - - if( (res = vorbis_synthesis_headerin(&this->vi,&this->vc,&this->op)) < 0 ){ - /* error case; not a vorbis header */ - xine_log(this->stream->xine, XINE_LOG_MSG, "libvorbis: this bitstream does not contain vorbis audio data. Following first 64 bytes (return: %d).\n", res); - xine_hexdump(this->op.packet, this->op.bytes < 64 ? this->op.bytes : 64); - return; - } - - this->header_count--; - - if (!this->header_count) { - - int mode = AO_CAP_MODE_MONO; - - get_metadata (this); - - mode = _x_ao_channels2mode(this->vi.channels); - - this->convsize=MAX_NUM_SAMPLES/this->vi.channels; - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open(this->stream->audio_out, - this->stream, - 16, - this->vi.rate, - mode) ; - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, - this->vi.bitrate_nominal); - - } - - /* OK, got and parsed all three headers. Initialize the Vorbis - * packet->PCM decoder. */ - lprintf("all three headers parsed. initializing decoder.\n"); - /* initialize central decode state */ - vorbis_synthesis_init(&this->vd,&this->vi); - /* initialize local state for most of the decode so multiple - * block decodes can proceed in parallel. We could init - * multiple vorbis_block structures for vd here */ - vorbis_block_init(&this->vd,&this->vb); - } - } - - } else if (this->output_open) { - - float **pcm; - int samples; - - if(vorbis_synthesis(&this->vb,&this->op)==0) - vorbis_synthesis_blockin(&this->vd,&this->vb); - - if (buf->pts!=0) - this->pts=buf->pts; - - while ((samples=vorbis_synthesis_pcmout(&this->vd,&pcm))>0){ - - /* **pcm is a multichannel float vector. In stereo, for - * example, pcm[0][...] is left, and pcm[1][...] is right. - * samples is the size of each channel. Convert the float - * values (-1.<=range<=1.) to whatever PCM format and write - * it out - */ - - int i,j; - int clipflag=0; - int bout=(samplesconvsize?samples:this->convsize); - audio_buffer_t *audio_buffer; - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - /* convert floats to 16 bit signed ints (host order) and - interleave */ - for(i=0;ivi.channels;i++){ - ogg_int16_t *ptr=audio_buffer->mem+i; - float *mono=pcm[i]; - for(j=0;j32767){ - val=32767; - clipflag=1; - } - if(val<-32768){ - val=-32768; - clipflag=1; - } - *ptr=val; - ptr+=this->vi.channels; - } - } - - audio_buffer->vpts = this->pts; - this->pts=0; - audio_buffer->num_frames = bout; - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - buf->pts=0; - - /* tell libvorbis how many samples we actually consumed */ - vorbis_synthesis_read(&this->vd,bout); - } - } - lprintf("output not open\n"); -} - -static void vorbis_dispose (audio_decoder_t *this_gen) { - - vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; - - if( !this->header_count ) { - lprintf("deinitializing decoder\n"); - - vorbis_block_clear(&this->vb); - vorbis_dsp_clear(&this->vd); - } - - vorbis_comment_clear(&this->vc); - - vorbis_info_clear(&this->vi); /* must be called last */ - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - lprintf("libvorbis instance destroyed\n"); - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, - xine_stream_t *stream) { - - vorbis_decoder_t *this ; - - this = (vorbis_decoder_t *) xine_xmalloc (sizeof (vorbis_decoder_t)); - - this->audio_decoder.decode_data = vorbis_decode_data; - this->audio_decoder.reset = vorbis_reset; - this->audio_decoder.discontinuity = vorbis_discontinuity; - this->audio_decoder.dispose = vorbis_dispose; - this->stream = stream; - - this->output_open = 0; - this->header_count = 3; - this->convsize = 0; - - vorbis_info_init(&this->vi); - vorbis_comment_init(&this->vc); - - lprintf("libvorbis decoder instance created\n"); - - return (audio_decoder_t *) this; -} - -/* - * vorbis plugin class - */ - -static char *get_identifier (audio_decoder_class_t *this) { - return "vorbis"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "vorbis audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - vorbis_class_t *this; - - this = (vorbis_class_t *) xine_xmalloc (sizeof (vorbis_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_VORBIS, 0 - }; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "vorbis", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxineadec/Makefile.am b/src/libxineadec/Makefile.am index 373347aaa..f2e3b4aa0 100644 --- a/src/libxineadec/Makefile.am +++ b/src/libxineadec/Makefile.am @@ -6,10 +6,15 @@ SUBDIRS = gsm610 nosefart AM_LDFLAGS = $(xineplug_ldflags) +if HAVE_VORBIS +vorbis_module = xineplug_decode_vorbis.la +endif + xineplug_LTLIBRARIES = \ xineplug_decode_gsm610.la \ xineplug_decode_nsf.la \ - xineplug_decode_lpcm.la + xineplug_decode_lpcm.la \ + $(vorbis_module) xineplug_decode_gsm610_la_SOURCES = gsm610.c xineplug_decode_gsm610_la_CFLAGS = $(VISIBILITY_FLAG) @@ -22,3 +27,7 @@ xineplug_decode_nsf_la_LIBADD = $(XINE_LIB) -lm nosefart/libnosefart.la xineplug_decode_lpcm_la_SOURCES = xine_lpcm_decoder.c xineplug_decode_lpcm_la_CFLAGS = $(VISIBILITY_FLAG) xineplug_decode_lpcm_la_LIBADD = $(XINE_LIB) + +xineplug_decode_vorbis_la_SOURCES = xine_vorbis_decoder.c +xineplug_decode_vorbis_la_LIBADD = $(XINE_LIB) $(VORBIS_LIBS) $(OGG_LIBS) +xineplug_decode_vorbis_la_CFLAGS = $(VISIBILITY_FLAG) $(VORBIS_CFLAGS) diff --git a/src/libxineadec/xine_vorbis_decoder.c b/src/libxineadec/xine_vorbis_decoder.c new file mode 100644 index 000000000..ef8575949 --- /dev/null +++ b/src/libxineadec/xine_vorbis_decoder.c @@ -0,0 +1,354 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.48 2006/12/04 13:59:38 dgp85 Exp $ + * + * (ogg/)vorbis audio decoder plugin (libvorbis wrapper) for xine + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#define LOG_MODULE "vorbis_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" + +#include +#include + +#define MAX_NUM_SAMPLES 4096 + +typedef struct { + audio_decoder_class_t decoder_class; +} vorbis_class_t; + +typedef struct vorbis_decoder_s { + audio_decoder_t audio_decoder; + + int64_t pts; + + int output_sampling_rate; + int output_open; + int output_mode; + + ogg_packet op; /* we must use this struct to sent data to libvorbis */ + + /* vorbis stuff */ + vorbis_info vi; /* stores static vorbis bitstream settings */ + vorbis_comment vc; + vorbis_dsp_state vd; /* central working state for packet->PCM decoder */ + vorbis_block vb; /* local working state for packet->PCM decoder */ + + int16_t convbuffer[MAX_NUM_SAMPLES]; + int convsize; + + int header_count; + + xine_stream_t *stream; + +} vorbis_decoder_t; + + +static void vorbis_reset (audio_decoder_t *this_gen) { + + vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; + + if( !this->header_count ) + vorbis_block_init(&this->vd,&this->vb); +} + +static void vorbis_discontinuity (audio_decoder_t *this_gen) { + + vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; + + this->pts=0; +} + +/* Known vorbis comment keys from ogg123 sources*/ +static struct { + char *key; /* includes the '=' for programming convenience */ + int xine_metainfo_index; +} vorbis_comment_keys[] = { + {"ARTIST=", XINE_META_INFO_ARTIST}, + {"ALBUM=", XINE_META_INFO_ALBUM}, + {"TITLE=", XINE_META_INFO_TITLE}, + {"GENRE=", XINE_META_INFO_GENRE}, + {"DESCRIPTION=", XINE_META_INFO_COMMENT}, + {"COMMENT=", XINE_META_INFO_COMMENT}, + {"DATE=", XINE_META_INFO_YEAR}, + {"TRACKNUMBER=", XINE_META_INFO_TRACK_NUMBER}, + {NULL, 0} +}; + +static void get_metadata (vorbis_decoder_t *this) { + + char **ptr=this->vc.user_comments; + while(*ptr){ + + char *comment = *ptr; + int i; + + lprintf("%s\n", comment); + + for (i = 0; vorbis_comment_keys[i].key != NULL; i++) { + + if ( !strncasecmp (vorbis_comment_keys[i].key, comment, + strlen(vorbis_comment_keys[i].key)) ) { + + lprintf ("known metadata %d %d\n", + i, vorbis_comment_keys[i].xine_metainfo_index); + + _x_meta_info_set_utf8(this->stream, vorbis_comment_keys[i].xine_metainfo_index, + comment + strlen(vorbis_comment_keys[i].key)); + + } + } + ++ptr; + } + + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "vorbis"); +} + +static void vorbis_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; + + memset( &this->op, 0, sizeof(this->op) ); + this->op.packet = buf->content; + this->op.bytes = buf->size; + + if ( (buf->decoder_flags & BUF_FLAG_HEADER) && + !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { + lprintf ("%d headers to go\n", this->header_count); + + if (this->header_count) { + int res = 0; + + if (this->header_count == 3) + this->op.b_o_s = 1; + + + if( (res = vorbis_synthesis_headerin(&this->vi,&this->vc,&this->op)) < 0 ){ + /* error case; not a vorbis header */ + xine_log(this->stream->xine, XINE_LOG_MSG, "libvorbis: this bitstream does not contain vorbis audio data. Following first 64 bytes (return: %d).\n", res); + xine_hexdump(this->op.packet, this->op.bytes < 64 ? this->op.bytes : 64); + return; + } + + this->header_count--; + + if (!this->header_count) { + + int mode = AO_CAP_MODE_MONO; + + get_metadata (this); + + mode = _x_ao_channels2mode(this->vi.channels); + + this->convsize=MAX_NUM_SAMPLES/this->vi.channels; + + if (!this->output_open) { + this->output_open = this->stream->audio_out->open(this->stream->audio_out, + this->stream, + 16, + this->vi.rate, + mode) ; + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, + this->vi.bitrate_nominal); + + } + + /* OK, got and parsed all three headers. Initialize the Vorbis + * packet->PCM decoder. */ + lprintf("all three headers parsed. initializing decoder.\n"); + /* initialize central decode state */ + vorbis_synthesis_init(&this->vd,&this->vi); + /* initialize local state for most of the decode so multiple + * block decodes can proceed in parallel. We could init + * multiple vorbis_block structures for vd here */ + vorbis_block_init(&this->vd,&this->vb); + } + } + + } else if (this->output_open) { + + float **pcm; + int samples; + + if(vorbis_synthesis(&this->vb,&this->op)==0) + vorbis_synthesis_blockin(&this->vd,&this->vb); + + if (buf->pts!=0) + this->pts=buf->pts; + + while ((samples=vorbis_synthesis_pcmout(&this->vd,&pcm))>0){ + + /* **pcm is a multichannel float vector. In stereo, for + * example, pcm[0][...] is left, and pcm[1][...] is right. + * samples is the size of each channel. Convert the float + * values (-1.<=range<=1.) to whatever PCM format and write + * it out + */ + + int i,j; + int clipflag=0; + int bout=(samplesconvsize?samples:this->convsize); + audio_buffer_t *audio_buffer; + + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + + /* convert floats to 16 bit signed ints (host order) and + interleave */ + for(i=0;ivi.channels;i++){ + ogg_int16_t *ptr=audio_buffer->mem+i; + float *mono=pcm[i]; + for(j=0;j32767){ + val=32767; + clipflag=1; + } + if(val<-32768){ + val=-32768; + clipflag=1; + } + *ptr=val; + ptr+=this->vi.channels; + } + } + + audio_buffer->vpts = this->pts; + this->pts=0; + audio_buffer->num_frames = bout; + + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + + buf->pts=0; + + /* tell libvorbis how many samples we actually consumed */ + vorbis_synthesis_read(&this->vd,bout); + } + } + lprintf("output not open\n"); +} + +static void vorbis_dispose (audio_decoder_t *this_gen) { + + vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; + + if( !this->header_count ) { + lprintf("deinitializing decoder\n"); + + vorbis_block_clear(&this->vb); + vorbis_dsp_clear(&this->vd); + } + + vorbis_comment_clear(&this->vc); + + vorbis_info_clear(&this->vi); /* must be called last */ + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + lprintf("libvorbis instance destroyed\n"); + + free (this_gen); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, + xine_stream_t *stream) { + + vorbis_decoder_t *this ; + + this = (vorbis_decoder_t *) xine_xmalloc (sizeof (vorbis_decoder_t)); + + this->audio_decoder.decode_data = vorbis_decode_data; + this->audio_decoder.reset = vorbis_reset; + this->audio_decoder.discontinuity = vorbis_discontinuity; + this->audio_decoder.dispose = vorbis_dispose; + this->stream = stream; + + this->output_open = 0; + this->header_count = 3; + this->convsize = 0; + + vorbis_info_init(&this->vi); + vorbis_comment_init(&this->vc); + + lprintf("libvorbis decoder instance created\n"); + + return (audio_decoder_t *) this; +} + +/* + * vorbis plugin class + */ + +static char *get_identifier (audio_decoder_class_t *this) { + return "vorbis"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "vorbis audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + vorbis_class_t *this; + + this = (vorbis_class_t *) xine_xmalloc (sizeof (vorbis_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_VORBIS, 0 + }; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "vorbis", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From 961c91517ea9f2b8342b1f84e9afeb1afbf89ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:14:43 +0200 Subject: Move the Theora decoder from libtheora to libxinevdec, as it's a single file. --HG-- rename : src/libtheora/xine_decoder.c => src/libxinevdec/xine_theora_decoder.c --- src/Makefile.am | 1 - src/libtheora/Makefile.am | 15 -- src/libtheora/xine_decoder.c | 402 ---------------------------------- src/libxinevdec/Makefile.am | 8 + src/libxinevdec/xine_theora_decoder.c | 402 ++++++++++++++++++++++++++++++++++ 5 files changed, 410 insertions(+), 418 deletions(-) delete mode 100644 src/libtheora/Makefile.am delete mode 100644 src/libtheora/xine_decoder.c create mode 100644 src/libxinevdec/xine_theora_decoder.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 86832bf18..e6c684819 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,6 @@ SUBDIRS = \ libw32dll \ libxinevdec \ libxineadec \ - libtheora \ libspeex \ libreal \ libfaad \ diff --git a/src/libtheora/Makefile.am b/src/libtheora/Makefile.am deleted file mode 100644 index d3813765d..000000000 --- a/src/libtheora/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -AM_CFLAGS = $(THEORA_CFLAGS) - -libdir = $(XINE_PLUGINDIR) - -if HAVE_THEORA -theora_module = xineplug_decode_theora.la -endif - -lib_LTLIBRARIES = $(theora_module) - -xineplug_decode_theora_la_SOURCES = xine_decoder.c -xineplug_decode_theora_la_LIBADD = $(OGG_LIBS) $(THEORA_LIBS) $(XINE_LIB) -xineplug_decode_theora_la_LDFLAGS = -avoid-version -module diff --git a/src/libtheora/xine_decoder.c b/src/libtheora/xine_decoder.c deleted file mode 100644 index 032f8800f..000000000 --- a/src/libtheora/xine_decoder.c +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Copyright (C) 2001-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.26 2006/07/10 22:08:30 dgp85 Exp $ - * - * xine decoder plugin using libtheora - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "theora_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "metronom.h" -#include "xineutils.h" - -typedef struct theora_class_s { - video_decoder_class_t decoder_class; -} theora_class_t; - -typedef struct theora_decoder_s { - video_decoder_t theora_decoder; - theora_class_t *class; - theora_info t_info; - theora_comment t_comment; - theora_state t_state; - ogg_packet op; - yuv_buffer yuv; - xine_stream_t* stream; - int reject; - int op_max_size; - char* packet; - int done; - int width, height; - double ratio; - int offset_x, offset_y; - int frame_duration; - int skipframes; - int hp_read; - int initialized; -} theora_decoder_t; - -static void readin_op (theora_decoder_t *this, char* src, int size) { - if ( this->done+size > this->op_max_size) { - while (this->op_max_size < this->done+size) - this->op_max_size=this->op_max_size*2; - this->packet=realloc(this->packet, this->op_max_size); - this->op.packet=this->packet; - } - xine_fast_memcpy ( this->packet+this->done, src, size); - this->done=this->done+size; -} - -static void yuv2frame(yuv_buffer *yuv, vo_frame_t *frame, int offset_x, int offset_y) { - int i; - int crop_offset; - - /* fixme - direct rendering (exchaning pointers) may be possible. - * frame->base[0] = yuv->y could work if one could change the - * pitches[0,1,2] values, and rely on the drawing routine using - * the new pitches. With cropping and offsets, it's a bit trickier, - * but it would still be possible. - * Attempts at doing this have yielded nothing but SIGSEVs so far. - */ - - /* Copy yuv data onto the frame. Cropping and offset as specified - * by the frame_width, frame_height, offset_x and offset_y fields - * in the theora header is carried out. - */ - - crop_offset=offset_x+yuv->y_stride*offset_y; - for(i=0;iheight;i++) - xine_fast_memcpy(frame->base[0]+frame->pitches[0]*i, - yuv->y+crop_offset+yuv->y_stride*i, - frame->width); - - crop_offset=(offset_x/2)+(yuv->uv_stride)*(offset_y/2); - for(i=0;iheight/2;i++){ - xine_fast_memcpy(frame->base[1]+frame->pitches[1]*i, - yuv->u+crop_offset+yuv->uv_stride*i, - frame->width/2); - xine_fast_memcpy(frame->base[2]+frame->pitches[2]*i, - yuv->v+crop_offset+yuv->uv_stride*i, - frame->width/2); - - } -} - -static int collect_data (theora_decoder_t *this, buf_element_t *buf ) { - /* Assembles an ogg_packet which was sent with send_ogg_packet over xinebuffers */ - /* this->done, this->rejected, this->op and this->decoder->flags are needed*/ - int op_size = sizeof (ogg_packet); - - if (buf->decoder_flags & BUF_FLAG_FRAME_START) { - this->done=0; /*start from the beginnig*/ - this->reject=0;/*new packet - new try*/ - - /*copy the ogg_packet struct and the sum, correct the adress of the packet*/ - xine_fast_memcpy (&this->op, buf->content, op_size); - this->op.packet=this->packet; - - readin_op (this, buf->content + op_size, buf->size - op_size ); - /*read the rest of the data*/ - - } else { - if (this->done==0 || this->reject) { - /*we are starting to collect an packet without the beginnig - reject the rest*/ - printf ("libtheora: rejecting packet\n"); - this->reject=1; - return 0; - } - readin_op (this, buf->content, buf->size ); - } - - if ((buf->decoder_flags & BUF_FLAG_FRAME_END) && !this->reject) { - if ( this->done != this->op.bytes ) { - printf ("libtheora: A packet changed its size during transfer - rejected\n"); - printf (" size %d should be %ld\n", this->done , this->op.bytes); - this->op.bytes=this->done; - } - return 1; - } - return 0; -} - -static void theora_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - /* - * decode data from buf and feed decoded frames to - * video output - */ - theora_decoder_t *this = (theora_decoder_t *) this_gen; - vo_frame_t *frame; - yuv_buffer yuv; - int ret; - - if (!collect_data(this, buf)) return; - /*return, until a entire packets is collected*/ - - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { - /*get the first 3 packets and decode the header during preview*/ - - if (this->hp_read==0) { - /*decode first hp*/ - if (theora_decode_header(&this->t_info, &this->t_comment, &this->op)>=0) { - this->hp_read++; - return; - } - } - - if (this->hp_read==1) { - /*decode three header packets*/ - if (theora_decode_header(&this->t_info, &this->t_comment,&this->op)) { - printf ("libtheora: Was unable to decode header #%d, corrupt stream?\n",this->hp_read); - } else { - this->hp_read++; - return; - } - } - - if (this->hp_read==2) { - if (theora_decode_header(&this->t_info, &this->t_comment,&this->op)) { - printf ("libtheora: Was unable to decode header #%d, corrupt stream?\n",this->hp_read); - } - /*headers are now decoded. initialize the decoder*/ - theora_decode_init (&this->t_state, &this->t_info); - - lprintf("theora stream is Theora %dx%d %.02f fps video.\n" - " frame content is %dx%d with offset (%d,%d).\n" - " pixel aspect is %d:%d.\n", - this->t_info.width,this->t_info.height, - (double)this->t_info.fps_numerator/this->t_info.fps_denominator, - this->t_info.frame_width, this->t_info.frame_height, - this->t_info.offset_x, this->t_info.offset_y, - this->t_info.aspect_numerator, this->t_info.aspect_denominator); - - this->frame_duration=((int64_t)90000*this->t_info.fps_denominator)/this->t_info.fps_numerator; - this->width=this->t_info.frame_width; - this->height=this->t_info.frame_height; - if (this->t_info.aspect_numerator==0 || this->t_info.aspect_denominator==0) - /* 0-values are undefined, so don't do any scaling. */ - this->ratio=(double)this->width/(double)this->height; - else - /* Yes, this video needs to be scaled. */ - this->ratio=(double)(this->width*this->t_info.aspect_numerator) / - (double)(this->height*this->t_info.aspect_denominator); - this->offset_x=this->t_info.offset_x; - this->offset_y=this->t_info.offset_y; - this->initialized=1; - this->hp_read++; - } - - } else if (buf->decoder_flags & BUF_FLAG_HEADER) { - /*ignore headerpackets*/ - - return; - - } else { - /*decode videodata*/ - - if (!this->initialized) { - printf ("libtheora: cannot decode stream without header\n"); - return; - } - - ret=theora_decode_packetin( &this->t_state, &this->op); - - if ( ret!=0) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "libtheora:Received an bad packet\n"); - } else if (!this->skipframes) { - - theora_decode_YUVout(&this->t_state,&yuv); - - /*fixme - aspectratio from theora is not considered*/ - frame = this->stream->video_out->get_frame( this->stream->video_out, - this->width, this->height, - this->ratio, - XINE_IMGFMT_YV12, - VO_BOTH_FIELDS); - yuv2frame(&yuv, frame, this->offset_x, this->offset_y); - - frame->pts = buf->pts; - frame->duration=this->frame_duration; - this->skipframes=frame->draw(frame, this->stream); - frame->free(frame); - } else { - this->skipframes=this->skipframes-1; - } - } -} - - -static void theora_flush (video_decoder_t *this_gen) { - /* - * flush out any frames that are still stored in the decoder - */ - theora_decoder_t *this = (theora_decoder_t *) this_gen; - this->skipframes=0; -} - -static void theora_reset (video_decoder_t *this_gen) { - /* - * reset decoder after engine flush (prepare for new - * video data not related to recently decoded data) - */ - theora_decoder_t *this = (theora_decoder_t *) this_gen; - this->skipframes=0; -} - -static void theora_discontinuity (video_decoder_t *this_gen) { - /* - * inform decoder that a time reference discontinuity has happened. - * that is, it must forget any currently held pts value - */ - theora_decoder_t *this = (theora_decoder_t *) this_gen; - this->skipframes=0; -} - -static void theora_dispose (video_decoder_t *this_gen) { - /* - * close down, free all resources - */ - - theora_decoder_t *this = (theora_decoder_t *) this_gen; - - lprintf ("dispose \n"); - - theora_clear (&this->t_state); - theora_comment_clear (&this->t_comment); - theora_info_clear (&this->t_info); - this->stream->video_out->close(this->stream->video_out, this->stream); - free (this->packet); - free (this); -} - -static video_decoder_t *theora_open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - /* - * open a new instance of this plugin class - */ - - theora_decoder_t *this ; - - this = (theora_decoder_t *) xine_xmalloc (sizeof (theora_decoder_t)); - - this->theora_decoder.decode_data = theora_decode_data; - this->theora_decoder.flush = theora_flush; - this->theora_decoder.reset = theora_reset; - this->theora_decoder.discontinuity = theora_discontinuity; - this->theora_decoder.dispose = theora_dispose; - - this->stream = stream; - this->class = (theora_class_t *) class_gen; - - this->op_max_size = 4096; - this->packet = malloc(this->op_max_size); - - this->done = 0; - - this->stream = stream; - - this->initialized = 0; - - theora_comment_init (&this->t_comment); - theora_info_init (&this->t_info); - stream->video_out->open (stream->video_out, stream); - - return &this->theora_decoder; - -} - -/* - * theora plugin class - */ - -static char *theora_get_identifier (video_decoder_class_t *this) { - /* - * return short, human readable identifier for this plugin class - */ - return "theora video"; -} - -static char *theora_get_description (video_decoder_class_t *this) { - /* - * return human readable (verbose = 1 line) description for - * this plugin class - */ - return "theora video decoder plugin"; -} - -static void theora_dispose_class (video_decoder_class_t *this) { - /* - * free all class-related resources - */ - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - /*initialize our plugin*/ - theora_class_t *this; - - this = (theora_class_t *) xine_xmalloc (sizeof (theora_class_t)); - - this->decoder_class.open_plugin = theora_open_plugin; - this->decoder_class.get_identifier = theora_get_identifier; - this->decoder_class.get_description = theora_get_description; - this->decoder_class.dispose = theora_dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t supported_types[] = { BUF_VIDEO_THEORA, 0 }; - -static const decoder_info_t dec_info_video = { - supported_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "theora", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/Makefile.am b/src/libxinevdec/Makefile.am index 903399cbb..87ee050e6 100644 --- a/src/libxinevdec/Makefile.am +++ b/src/libxinevdec/Makefile.am @@ -13,8 +13,13 @@ if HAVE_GDK_PIXBUF gdkpixbuf_module = xineplug_decode_gdk_pixbuf.la endif +if HAVE_THEORA +theora_module = xineplug_decode_theora.la +endif + xineplug_LTLIBRARIES = $(image_module) \ $(gdkpixbuf_module) \ + $(theora_module) \ xineplug_decode_bitplane.la \ xineplug_decode_rgb.la \ xineplug_decode_yuv.la @@ -36,3 +41,6 @@ xineplug_decode_gdk_pixbuf_la_SOURCES = gdkpixbuf.c xineplug_decode_gdk_pixbuf_la_CFLAGS = $(AM_CFLAGS) $(GDK_PIXBUF_CFLAGS) xineplug_decode_gdk_pixbuf_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) $(GDK_PIXBUF_LIBS) +xineplug_decode_theora_la_SOURCES = xine_theora_decoder.c +xineplug_decode_theora_la_CFLAGS = $(AM_CFLAGS) $(OGG_CFLAGS) $(THEORA_CFLAGS) +xineplug_decode_theora_la_LIBADD = $(XINE_LIB) $(OGG_LIBS) $(THEORA_LIBS) diff --git a/src/libxinevdec/xine_theora_decoder.c b/src/libxinevdec/xine_theora_decoder.c new file mode 100644 index 000000000..032f8800f --- /dev/null +++ b/src/libxinevdec/xine_theora_decoder.c @@ -0,0 +1,402 @@ +/* + * Copyright (C) 2001-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.26 2006/07/10 22:08:30 dgp85 Exp $ + * + * xine decoder plugin using libtheora + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "theora_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "video_out.h" +#include "buffer.h" +#include "metronom.h" +#include "xineutils.h" + +typedef struct theora_class_s { + video_decoder_class_t decoder_class; +} theora_class_t; + +typedef struct theora_decoder_s { + video_decoder_t theora_decoder; + theora_class_t *class; + theora_info t_info; + theora_comment t_comment; + theora_state t_state; + ogg_packet op; + yuv_buffer yuv; + xine_stream_t* stream; + int reject; + int op_max_size; + char* packet; + int done; + int width, height; + double ratio; + int offset_x, offset_y; + int frame_duration; + int skipframes; + int hp_read; + int initialized; +} theora_decoder_t; + +static void readin_op (theora_decoder_t *this, char* src, int size) { + if ( this->done+size > this->op_max_size) { + while (this->op_max_size < this->done+size) + this->op_max_size=this->op_max_size*2; + this->packet=realloc(this->packet, this->op_max_size); + this->op.packet=this->packet; + } + xine_fast_memcpy ( this->packet+this->done, src, size); + this->done=this->done+size; +} + +static void yuv2frame(yuv_buffer *yuv, vo_frame_t *frame, int offset_x, int offset_y) { + int i; + int crop_offset; + + /* fixme - direct rendering (exchaning pointers) may be possible. + * frame->base[0] = yuv->y could work if one could change the + * pitches[0,1,2] values, and rely on the drawing routine using + * the new pitches. With cropping and offsets, it's a bit trickier, + * but it would still be possible. + * Attempts at doing this have yielded nothing but SIGSEVs so far. + */ + + /* Copy yuv data onto the frame. Cropping and offset as specified + * by the frame_width, frame_height, offset_x and offset_y fields + * in the theora header is carried out. + */ + + crop_offset=offset_x+yuv->y_stride*offset_y; + for(i=0;iheight;i++) + xine_fast_memcpy(frame->base[0]+frame->pitches[0]*i, + yuv->y+crop_offset+yuv->y_stride*i, + frame->width); + + crop_offset=(offset_x/2)+(yuv->uv_stride)*(offset_y/2); + for(i=0;iheight/2;i++){ + xine_fast_memcpy(frame->base[1]+frame->pitches[1]*i, + yuv->u+crop_offset+yuv->uv_stride*i, + frame->width/2); + xine_fast_memcpy(frame->base[2]+frame->pitches[2]*i, + yuv->v+crop_offset+yuv->uv_stride*i, + frame->width/2); + + } +} + +static int collect_data (theora_decoder_t *this, buf_element_t *buf ) { + /* Assembles an ogg_packet which was sent with send_ogg_packet over xinebuffers */ + /* this->done, this->rejected, this->op and this->decoder->flags are needed*/ + int op_size = sizeof (ogg_packet); + + if (buf->decoder_flags & BUF_FLAG_FRAME_START) { + this->done=0; /*start from the beginnig*/ + this->reject=0;/*new packet - new try*/ + + /*copy the ogg_packet struct and the sum, correct the adress of the packet*/ + xine_fast_memcpy (&this->op, buf->content, op_size); + this->op.packet=this->packet; + + readin_op (this, buf->content + op_size, buf->size - op_size ); + /*read the rest of the data*/ + + } else { + if (this->done==0 || this->reject) { + /*we are starting to collect an packet without the beginnig + reject the rest*/ + printf ("libtheora: rejecting packet\n"); + this->reject=1; + return 0; + } + readin_op (this, buf->content, buf->size ); + } + + if ((buf->decoder_flags & BUF_FLAG_FRAME_END) && !this->reject) { + if ( this->done != this->op.bytes ) { + printf ("libtheora: A packet changed its size during transfer - rejected\n"); + printf (" size %d should be %ld\n", this->done , this->op.bytes); + this->op.bytes=this->done; + } + return 1; + } + return 0; +} + +static void theora_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { + /* + * decode data from buf and feed decoded frames to + * video output + */ + theora_decoder_t *this = (theora_decoder_t *) this_gen; + vo_frame_t *frame; + yuv_buffer yuv; + int ret; + + if (!collect_data(this, buf)) return; + /*return, until a entire packets is collected*/ + + if ( (buf->decoder_flags & BUF_FLAG_HEADER) && + !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { + /*get the first 3 packets and decode the header during preview*/ + + if (this->hp_read==0) { + /*decode first hp*/ + if (theora_decode_header(&this->t_info, &this->t_comment, &this->op)>=0) { + this->hp_read++; + return; + } + } + + if (this->hp_read==1) { + /*decode three header packets*/ + if (theora_decode_header(&this->t_info, &this->t_comment,&this->op)) { + printf ("libtheora: Was unable to decode header #%d, corrupt stream?\n",this->hp_read); + } else { + this->hp_read++; + return; + } + } + + if (this->hp_read==2) { + if (theora_decode_header(&this->t_info, &this->t_comment,&this->op)) { + printf ("libtheora: Was unable to decode header #%d, corrupt stream?\n",this->hp_read); + } + /*headers are now decoded. initialize the decoder*/ + theora_decode_init (&this->t_state, &this->t_info); + + lprintf("theora stream is Theora %dx%d %.02f fps video.\n" + " frame content is %dx%d with offset (%d,%d).\n" + " pixel aspect is %d:%d.\n", + this->t_info.width,this->t_info.height, + (double)this->t_info.fps_numerator/this->t_info.fps_denominator, + this->t_info.frame_width, this->t_info.frame_height, + this->t_info.offset_x, this->t_info.offset_y, + this->t_info.aspect_numerator, this->t_info.aspect_denominator); + + this->frame_duration=((int64_t)90000*this->t_info.fps_denominator)/this->t_info.fps_numerator; + this->width=this->t_info.frame_width; + this->height=this->t_info.frame_height; + if (this->t_info.aspect_numerator==0 || this->t_info.aspect_denominator==0) + /* 0-values are undefined, so don't do any scaling. */ + this->ratio=(double)this->width/(double)this->height; + else + /* Yes, this video needs to be scaled. */ + this->ratio=(double)(this->width*this->t_info.aspect_numerator) / + (double)(this->height*this->t_info.aspect_denominator); + this->offset_x=this->t_info.offset_x; + this->offset_y=this->t_info.offset_y; + this->initialized=1; + this->hp_read++; + } + + } else if (buf->decoder_flags & BUF_FLAG_HEADER) { + /*ignore headerpackets*/ + + return; + + } else { + /*decode videodata*/ + + if (!this->initialized) { + printf ("libtheora: cannot decode stream without header\n"); + return; + } + + ret=theora_decode_packetin( &this->t_state, &this->op); + + if ( ret!=0) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "libtheora:Received an bad packet\n"); + } else if (!this->skipframes) { + + theora_decode_YUVout(&this->t_state,&yuv); + + /*fixme - aspectratio from theora is not considered*/ + frame = this->stream->video_out->get_frame( this->stream->video_out, + this->width, this->height, + this->ratio, + XINE_IMGFMT_YV12, + VO_BOTH_FIELDS); + yuv2frame(&yuv, frame, this->offset_x, this->offset_y); + + frame->pts = buf->pts; + frame->duration=this->frame_duration; + this->skipframes=frame->draw(frame, this->stream); + frame->free(frame); + } else { + this->skipframes=this->skipframes-1; + } + } +} + + +static void theora_flush (video_decoder_t *this_gen) { + /* + * flush out any frames that are still stored in the decoder + */ + theora_decoder_t *this = (theora_decoder_t *) this_gen; + this->skipframes=0; +} + +static void theora_reset (video_decoder_t *this_gen) { + /* + * reset decoder after engine flush (prepare for new + * video data not related to recently decoded data) + */ + theora_decoder_t *this = (theora_decoder_t *) this_gen; + this->skipframes=0; +} + +static void theora_discontinuity (video_decoder_t *this_gen) { + /* + * inform decoder that a time reference discontinuity has happened. + * that is, it must forget any currently held pts value + */ + theora_decoder_t *this = (theora_decoder_t *) this_gen; + this->skipframes=0; +} + +static void theora_dispose (video_decoder_t *this_gen) { + /* + * close down, free all resources + */ + + theora_decoder_t *this = (theora_decoder_t *) this_gen; + + lprintf ("dispose \n"); + + theora_clear (&this->t_state); + theora_comment_clear (&this->t_comment); + theora_info_clear (&this->t_info); + this->stream->video_out->close(this->stream->video_out, this->stream); + free (this->packet); + free (this); +} + +static video_decoder_t *theora_open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { + + /* + * open a new instance of this plugin class + */ + + theora_decoder_t *this ; + + this = (theora_decoder_t *) xine_xmalloc (sizeof (theora_decoder_t)); + + this->theora_decoder.decode_data = theora_decode_data; + this->theora_decoder.flush = theora_flush; + this->theora_decoder.reset = theora_reset; + this->theora_decoder.discontinuity = theora_discontinuity; + this->theora_decoder.dispose = theora_dispose; + + this->stream = stream; + this->class = (theora_class_t *) class_gen; + + this->op_max_size = 4096; + this->packet = malloc(this->op_max_size); + + this->done = 0; + + this->stream = stream; + + this->initialized = 0; + + theora_comment_init (&this->t_comment); + theora_info_init (&this->t_info); + stream->video_out->open (stream->video_out, stream); + + return &this->theora_decoder; + +} + +/* + * theora plugin class + */ + +static char *theora_get_identifier (video_decoder_class_t *this) { + /* + * return short, human readable identifier for this plugin class + */ + return "theora video"; +} + +static char *theora_get_description (video_decoder_class_t *this) { + /* + * return human readable (verbose = 1 line) description for + * this plugin class + */ + return "theora video decoder plugin"; +} + +static void theora_dispose_class (video_decoder_class_t *this) { + /* + * free all class-related resources + */ + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + /*initialize our plugin*/ + theora_class_t *this; + + this = (theora_class_t *) xine_xmalloc (sizeof (theora_class_t)); + + this->decoder_class.open_plugin = theora_open_plugin; + this->decoder_class.get_identifier = theora_get_identifier; + this->decoder_class.get_description = theora_get_description; + this->decoder_class.dispose = theora_dispose_class; + + return this; +} + +/* + * exported plugin catalog entry + */ + +static uint32_t supported_types[] = { BUF_VIDEO_THEORA, 0 }; + +static const decoder_info_t dec_info_video = { + supported_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_VIDEO_DECODER, 18, "theora", XINE_VERSION_CODE, &dec_info_video, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From 63707aa6026241c7040b8cee59032aed10559e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:18:45 +0200 Subject: Move the Speex decoder from libspeex to libxineadec, as it's a single file. --HG-- rename : src/libspeex/xine_decoder.c => src/libxineadec/xine_speex_decoder.c --- src/Makefile.am | 1 - src/libspeex/Makefile.am | 14 -- src/libspeex/xine_decoder.c | 436 ----------------------------------- src/libxineadec/Makefile.am | 11 +- src/libxineadec/xine_speex_decoder.c | 436 +++++++++++++++++++++++++++++++++++ 5 files changed, 446 insertions(+), 452 deletions(-) delete mode 100644 src/libspeex/Makefile.am delete mode 100644 src/libspeex/xine_decoder.c create mode 100644 src/libxineadec/xine_speex_decoder.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index e6c684819..6718b4805 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,6 @@ SUBDIRS = \ libw32dll \ libxinevdec \ libxineadec \ - libspeex \ libreal \ libfaad \ libmusepack \ diff --git a/src/libspeex/Makefile.am b/src/libspeex/Makefile.am deleted file mode 100644 index bfe6f35b9..000000000 --- a/src/libspeex/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -libdir = $(XINE_PLUGINDIR) - -if HAVE_SPEEX -speex_module = xineplug_decode_speex.la -endif - -lib_LTLIBRARIES = $(speex_module) - -xineplug_decode_speex_la_SOURCES = xine_decoder.c -xineplug_decode_speex_la_LIBADD = $(SPEEX_LIBS) $(XINE_LIB) -xineplug_decode_speex_la_CFLAGS = $(VISIBILITY_FLAGS) $(SPEEX_CFLAGS) -xineplug_decode_speex_la_LDFLAGS = -avoid-version -module diff --git a/src/libspeex/xine_decoder.c b/src/libspeex/xine_decoder.c deleted file mode 100644 index b729dc3bb..000000000 --- a/src/libspeex/xine_decoder.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.22 2007/01/19 01:48:05 dgp85 Exp $ - * - * (ogg/)speex audio decoder plugin (libspeex wrapper) for xine - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#define LOG_MODULE "speex_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ -#define LOG_BUFFERS 0 - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" - -#include - -#include -#include -#include -#include - -#define MAX_FRAME_SIZE 2000 - -typedef struct { - audio_decoder_class_t decoder_class; -} speex_class_t; - -typedef struct speex_decoder_s { - audio_decoder_t audio_decoder; - - int64_t pts; - - int output_sampling_rate; - int output_open; - int output_mode; - - /* speex stuff */ - void *st; - int frame_size; - int rate; - int nframes; - int channels; - SpeexBits bits; - SpeexStereoState stereo; - int expect_metadata; - - float output[MAX_FRAME_SIZE]; - - int header_count; - - xine_stream_t *stream; - -} speex_decoder_t; - - -static void speex_reset (audio_decoder_t *this_gen) { - - speex_decoder_t *this = (speex_decoder_t *) this_gen; - - speex_bits_init (&this->bits); -} - -static void speex_discontinuity (audio_decoder_t *this_gen) { - - speex_decoder_t *this = (speex_decoder_t *) this_gen; - - this->pts=0; -} - -/* Known speex comment keys from ogg123 sources*/ -static struct { - char *key; /* includes the '=' for programming convenience */ - int xine_metainfo_index; -} speex_comment_keys[] = { - {"ARTIST=", XINE_META_INFO_ARTIST}, - {"ALBUM=", XINE_META_INFO_ALBUM}, - {"TITLE=", XINE_META_INFO_TITLE}, - {"GENRE=", XINE_META_INFO_GENRE}, - {"DESCRIPTION=", XINE_META_INFO_COMMENT}, - {"DATE=", XINE_META_INFO_YEAR}, - {NULL, 0} -}; - -#define readint(buf, base) (((buf[base+3]<<24)&0xff000000)| \ - ((buf[base+2]<<16)&0xff0000)| \ - ((buf[base+1]<<8)&0xff00)| \ - (buf[base]&0xff)) - -static -void read_metadata (speex_decoder_t *this, char * comments, int length) -{ - char * c = comments; - int len, i, nb_fields; - char * end; - - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "speex"); - - if (length < 8) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); - return; - } - - end = c+length; - len = readint (c, 0); - c += 4; - - if (c+len > end) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); - return; - } - -#ifdef LOG - /* Encoder */ - printf ("libspeex: "); - fwrite (c, 1, len, stdout); - printf ("\n"); -#endif - - c += len; - - if (c+4 > end) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); - return; - } - - nb_fields = readint (c, 0); - c += 4; - - for (i = 0; i < nb_fields; i++) { - if (c+4 > end) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); - return; - } - - len = readint (c, 0); - c += 4; - if (c+len > end) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); - return; - } - -#ifdef LOG - printf ("libspeex: "); - fwrite (c, 1, len, stdout); - printf ("\n"); -#endif - - for (i = 0; speex_comment_keys[i].key != NULL; i++) { - - if ( !strncasecmp (speex_comment_keys[i].key, c, - strlen(speex_comment_keys[i].key)) ) { - int keylen = strlen(speex_comment_keys[i].key); - char meta_info[(len - keylen) + 1]; - - lprintf ("known metadata %d %d\n", - i, speex_comment_keys[i].xine_metainfo_index); - - snprintf(meta_info, (len - keylen), "%s", c + keylen); - _x_meta_info_set_utf8(this->stream, speex_comment_keys[i].xine_metainfo_index, meta_info); - } - } - - c += len; - } -} - -static void speex_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - speex_decoder_t *this = (speex_decoder_t *) this_gen; - - llprintf (LOG_BUFFERS, "decode buf=%8p content=%8p flags=%08x\n", - buf, buf->content, buf->decoder_flags); - - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { - lprintf ("preview buffer, %d headers to go\n", this->header_count); - - if (this->header_count) { - - if (!this->st) { - SpeexMode * spx_mode; - SpeexHeader * spx_header; - int modeID; - int bitrate; - - speex_bits_init (&this->bits); - - spx_header = speex_packet_to_header (buf->content, buf->size); - - if (!spx_header) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: could not read Speex header\n"); - return; - } - - modeID = spx_header->mode; - spx_mode = (SpeexMode *) speex_mode_list[modeID]; - - if (spx_mode->bitstream_version != spx_header->mode_bitstream_version) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: incompatible Speex mode bitstream version\n"); - return; - } - - this->st = speex_decoder_init (spx_mode); - if (!this->st) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: decoder initialization failed\n"); - return; - } - - this->rate = spx_header->rate; - speex_decoder_ctl (this->st, SPEEX_SET_SAMPLING_RATE, &this->rate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, - this->rate); - - this->channels = spx_header->nb_channels; - if (this->channels == 2) { - SpeexCallback callback; - - callback.callback_id = SPEEX_INBAND_STEREO; - callback.func = speex_std_stereo_request_handler; - callback.data = &this->stereo; - speex_decoder_ctl (this->st, SPEEX_SET_HANDLER, &callback); - } - - this->nframes = spx_header->frames_per_packet; - if (!this->nframes) this->nframes = 1; - - speex_decoder_ctl (this->st, SPEEX_GET_FRAME_SIZE, &this->frame_size); - - speex_decoder_ctl (this->st, SPEEX_GET_BITRATE, &bitrate); - if (bitrate <= 1) bitrate = 16000; /* assume 16 kbit */ - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, bitrate); - - this->header_count += spx_header->extra_headers; - this->expect_metadata = 1; - - free (spx_header); - } else if (this->expect_metadata) { - read_metadata (this, buf->content, buf->size); - } - - this->header_count--; - - if (!this->header_count) { - int mode = _x_ao_channels2mode(this->channels); - - if (!this->output_open) { - this->output_open = - this->stream->audio_out->open(this->stream->audio_out, - this->stream, - 16, - this->rate, - mode); - lprintf ("this->output_open after attempt is %d\n", this->output_open); - } - } - } - - } else if (this->output_open) { - int i, j; - - audio_buffer_t *audio_buffer; - - audio_buffer = - this->stream->audio_out->get_buffer (this->stream->audio_out); - - speex_bits_read_from (&this->bits, buf->content, buf->size); - - for (j = 0; j < this->nframes; j++) { - int ret; - int bitrate; - ogg_int16_t * ptr = audio_buffer->mem; - - ret = speex_decode (this->st, &this->bits, this->output); - - if (ret==-1) - break; - if (ret==-2) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: Decoding error, corrupted stream?\n"); - break; - } - if (speex_bits_remaining(&this->bits)<0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: Decoding overflow, corrupted stream?\n"); - break; - } - - if (this->channels == 2) { - speex_decode_stereo (this->output, this->frame_size, &this->stereo); - } - - speex_decoder_ctl (this->st, SPEEX_GET_BITRATE, &bitrate); - if (bitrate <= 1) bitrate = 16000; /* assume 16 kbit */ - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, bitrate); - - /*PCM saturation (just in case)*/ - for (i=0; i < this->frame_size * this->channels; i++) - { - if (this->output[i]>32000.0) - this->output[i]=32000.0; - else if (this->output[i]<-32000.0) - this->output[i]=-32000.0; - } - - /*Convert to short and play */ - for (i=0; i< this->frame_size * this->channels; i++) { - *ptr++ = (ogg_int16_t)this->output[i]; - } - - audio_buffer->vpts = this->pts; - this->pts=0; - audio_buffer->num_frames = this->frame_size; - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - buf->pts=0; - - } - } - else { - llprintf (LOG_BUFFERS, "output not open\n"); - } -} - -static void speex_dispose (audio_decoder_t *this_gen) { - - speex_decoder_t *this = (speex_decoder_t *) this_gen; - - if (this->st) { - speex_decoder_destroy (this->st); - } - speex_bits_destroy (&this->bits); - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, - xine_stream_t *stream) { - - speex_decoder_t *this ; - static SpeexStereoState init_stereo = SPEEX_STEREO_STATE_INIT; - - this = (speex_decoder_t *) xine_xmalloc (sizeof (speex_decoder_t)); - - this->audio_decoder.decode_data = speex_decode_data; - this->audio_decoder.reset = speex_reset; - this->audio_decoder.discontinuity = speex_discontinuity; - this->audio_decoder.dispose = speex_dispose; - this->stream = stream; - - this->output_open = 0; - this->header_count = 1; - this->expect_metadata = 0; - - this->st = NULL; - - this->channels = 1; - - memcpy (&this->stereo, &init_stereo, sizeof (SpeexStereoState)); - - return (audio_decoder_t *) this; -} - -/* - * speex plugin class - */ - -static char *get_identifier (audio_decoder_class_t *this) { - return "speex"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "Speex audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - speex_class_t *this; - - this = (speex_class_t *) xine_xmalloc (sizeof (speex_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_SPEEX, 0 - }; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "speex", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxineadec/Makefile.am b/src/libxineadec/Makefile.am index f2e3b4aa0..b2ffcf078 100644 --- a/src/libxineadec/Makefile.am +++ b/src/libxineadec/Makefile.am @@ -10,11 +10,16 @@ if HAVE_VORBIS vorbis_module = xineplug_decode_vorbis.la endif +if HAVE_SPEEX +speex_module = xineplug_decode_speex.la +endif + xineplug_LTLIBRARIES = \ xineplug_decode_gsm610.la \ xineplug_decode_nsf.la \ xineplug_decode_lpcm.la \ - $(vorbis_module) + $(vorbis_module) \ + $(speex_module) xineplug_decode_gsm610_la_SOURCES = gsm610.c xineplug_decode_gsm610_la_CFLAGS = $(VISIBILITY_FLAG) @@ -31,3 +36,7 @@ xineplug_decode_lpcm_la_LIBADD = $(XINE_LIB) xineplug_decode_vorbis_la_SOURCES = xine_vorbis_decoder.c xineplug_decode_vorbis_la_LIBADD = $(XINE_LIB) $(VORBIS_LIBS) $(OGG_LIBS) xineplug_decode_vorbis_la_CFLAGS = $(VISIBILITY_FLAG) $(VORBIS_CFLAGS) + +xineplug_decode_speex_la_SOURCES = xine_speex_decoder.c +xineplug_decode_speex_la_LIBADD = $(XINE_LIB) $(SPEEX_LIBS) +xineplug_decode_speex_la_CFLAGS = $(VISIBILITY_FLAGS) $(SPEEX_CFLAGS) diff --git a/src/libxineadec/xine_speex_decoder.c b/src/libxineadec/xine_speex_decoder.c new file mode 100644 index 000000000..b729dc3bb --- /dev/null +++ b/src/libxineadec/xine_speex_decoder.c @@ -0,0 +1,436 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.22 2007/01/19 01:48:05 dgp85 Exp $ + * + * (ogg/)speex audio decoder plugin (libspeex wrapper) for xine + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#define LOG_MODULE "speex_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ +#define LOG_BUFFERS 0 + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" + +#include + +#include +#include +#include +#include + +#define MAX_FRAME_SIZE 2000 + +typedef struct { + audio_decoder_class_t decoder_class; +} speex_class_t; + +typedef struct speex_decoder_s { + audio_decoder_t audio_decoder; + + int64_t pts; + + int output_sampling_rate; + int output_open; + int output_mode; + + /* speex stuff */ + void *st; + int frame_size; + int rate; + int nframes; + int channels; + SpeexBits bits; + SpeexStereoState stereo; + int expect_metadata; + + float output[MAX_FRAME_SIZE]; + + int header_count; + + xine_stream_t *stream; + +} speex_decoder_t; + + +static void speex_reset (audio_decoder_t *this_gen) { + + speex_decoder_t *this = (speex_decoder_t *) this_gen; + + speex_bits_init (&this->bits); +} + +static void speex_discontinuity (audio_decoder_t *this_gen) { + + speex_decoder_t *this = (speex_decoder_t *) this_gen; + + this->pts=0; +} + +/* Known speex comment keys from ogg123 sources*/ +static struct { + char *key; /* includes the '=' for programming convenience */ + int xine_metainfo_index; +} speex_comment_keys[] = { + {"ARTIST=", XINE_META_INFO_ARTIST}, + {"ALBUM=", XINE_META_INFO_ALBUM}, + {"TITLE=", XINE_META_INFO_TITLE}, + {"GENRE=", XINE_META_INFO_GENRE}, + {"DESCRIPTION=", XINE_META_INFO_COMMENT}, + {"DATE=", XINE_META_INFO_YEAR}, + {NULL, 0} +}; + +#define readint(buf, base) (((buf[base+3]<<24)&0xff000000)| \ + ((buf[base+2]<<16)&0xff0000)| \ + ((buf[base+1]<<8)&0xff00)| \ + (buf[base]&0xff)) + +static +void read_metadata (speex_decoder_t *this, char * comments, int length) +{ + char * c = comments; + int len, i, nb_fields; + char * end; + + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "speex"); + + if (length < 8) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); + return; + } + + end = c+length; + len = readint (c, 0); + c += 4; + + if (c+len > end) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); + return; + } + +#ifdef LOG + /* Encoder */ + printf ("libspeex: "); + fwrite (c, 1, len, stdout); + printf ("\n"); +#endif + + c += len; + + if (c+4 > end) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); + return; + } + + nb_fields = readint (c, 0); + c += 4; + + for (i = 0; i < nb_fields; i++) { + if (c+4 > end) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); + return; + } + + len = readint (c, 0); + c += 4; + if (c+len > end) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: invalid/corrupted comments\n"); + return; + } + +#ifdef LOG + printf ("libspeex: "); + fwrite (c, 1, len, stdout); + printf ("\n"); +#endif + + for (i = 0; speex_comment_keys[i].key != NULL; i++) { + + if ( !strncasecmp (speex_comment_keys[i].key, c, + strlen(speex_comment_keys[i].key)) ) { + int keylen = strlen(speex_comment_keys[i].key); + char meta_info[(len - keylen) + 1]; + + lprintf ("known metadata %d %d\n", + i, speex_comment_keys[i].xine_metainfo_index); + + snprintf(meta_info, (len - keylen), "%s", c + keylen); + _x_meta_info_set_utf8(this->stream, speex_comment_keys[i].xine_metainfo_index, meta_info); + } + } + + c += len; + } +} + +static void speex_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + speex_decoder_t *this = (speex_decoder_t *) this_gen; + + llprintf (LOG_BUFFERS, "decode buf=%8p content=%8p flags=%08x\n", + buf, buf->content, buf->decoder_flags); + + if ( (buf->decoder_flags & BUF_FLAG_HEADER) && + !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { + lprintf ("preview buffer, %d headers to go\n", this->header_count); + + if (this->header_count) { + + if (!this->st) { + SpeexMode * spx_mode; + SpeexHeader * spx_header; + int modeID; + int bitrate; + + speex_bits_init (&this->bits); + + spx_header = speex_packet_to_header (buf->content, buf->size); + + if (!spx_header) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: could not read Speex header\n"); + return; + } + + modeID = spx_header->mode; + spx_mode = (SpeexMode *) speex_mode_list[modeID]; + + if (spx_mode->bitstream_version != spx_header->mode_bitstream_version) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: incompatible Speex mode bitstream version\n"); + return; + } + + this->st = speex_decoder_init (spx_mode); + if (!this->st) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: decoder initialization failed\n"); + return; + } + + this->rate = spx_header->rate; + speex_decoder_ctl (this->st, SPEEX_SET_SAMPLING_RATE, &this->rate); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, + this->rate); + + this->channels = spx_header->nb_channels; + if (this->channels == 2) { + SpeexCallback callback; + + callback.callback_id = SPEEX_INBAND_STEREO; + callback.func = speex_std_stereo_request_handler; + callback.data = &this->stereo; + speex_decoder_ctl (this->st, SPEEX_SET_HANDLER, &callback); + } + + this->nframes = spx_header->frames_per_packet; + if (!this->nframes) this->nframes = 1; + + speex_decoder_ctl (this->st, SPEEX_GET_FRAME_SIZE, &this->frame_size); + + speex_decoder_ctl (this->st, SPEEX_GET_BITRATE, &bitrate); + if (bitrate <= 1) bitrate = 16000; /* assume 16 kbit */ + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, bitrate); + + this->header_count += spx_header->extra_headers; + this->expect_metadata = 1; + + free (spx_header); + } else if (this->expect_metadata) { + read_metadata (this, buf->content, buf->size); + } + + this->header_count--; + + if (!this->header_count) { + int mode = _x_ao_channels2mode(this->channels); + + if (!this->output_open) { + this->output_open = + this->stream->audio_out->open(this->stream->audio_out, + this->stream, + 16, + this->rate, + mode); + lprintf ("this->output_open after attempt is %d\n", this->output_open); + } + } + } + + } else if (this->output_open) { + int i, j; + + audio_buffer_t *audio_buffer; + + audio_buffer = + this->stream->audio_out->get_buffer (this->stream->audio_out); + + speex_bits_read_from (&this->bits, buf->content, buf->size); + + for (j = 0; j < this->nframes; j++) { + int ret; + int bitrate; + ogg_int16_t * ptr = audio_buffer->mem; + + ret = speex_decode (this->st, &this->bits, this->output); + + if (ret==-1) + break; + if (ret==-2) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: Decoding error, corrupted stream?\n"); + break; + } + if (speex_bits_remaining(&this->bits)<0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libspeex: Decoding overflow, corrupted stream?\n"); + break; + } + + if (this->channels == 2) { + speex_decode_stereo (this->output, this->frame_size, &this->stereo); + } + + speex_decoder_ctl (this->st, SPEEX_GET_BITRATE, &bitrate); + if (bitrate <= 1) bitrate = 16000; /* assume 16 kbit */ + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, bitrate); + + /*PCM saturation (just in case)*/ + for (i=0; i < this->frame_size * this->channels; i++) + { + if (this->output[i]>32000.0) + this->output[i]=32000.0; + else if (this->output[i]<-32000.0) + this->output[i]=-32000.0; + } + + /*Convert to short and play */ + for (i=0; i< this->frame_size * this->channels; i++) { + *ptr++ = (ogg_int16_t)this->output[i]; + } + + audio_buffer->vpts = this->pts; + this->pts=0; + audio_buffer->num_frames = this->frame_size; + + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + + buf->pts=0; + + } + } + else { + llprintf (LOG_BUFFERS, "output not open\n"); + } +} + +static void speex_dispose (audio_decoder_t *this_gen) { + + speex_decoder_t *this = (speex_decoder_t *) this_gen; + + if (this->st) { + speex_decoder_destroy (this->st); + } + speex_bits_destroy (&this->bits); + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + free (this_gen); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, + xine_stream_t *stream) { + + speex_decoder_t *this ; + static SpeexStereoState init_stereo = SPEEX_STEREO_STATE_INIT; + + this = (speex_decoder_t *) xine_xmalloc (sizeof (speex_decoder_t)); + + this->audio_decoder.decode_data = speex_decode_data; + this->audio_decoder.reset = speex_reset; + this->audio_decoder.discontinuity = speex_discontinuity; + this->audio_decoder.dispose = speex_dispose; + this->stream = stream; + + this->output_open = 0; + this->header_count = 1; + this->expect_metadata = 0; + + this->st = NULL; + + this->channels = 1; + + memcpy (&this->stereo, &init_stereo, sizeof (SpeexStereoState)); + + return (audio_decoder_t *) this; +} + +/* + * speex plugin class + */ + +static char *get_identifier (audio_decoder_class_t *this) { + return "speex"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "Speex audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + speex_class_t *this; + + this = (speex_class_t *) xine_xmalloc (sizeof (speex_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_SPEEX, 0 + }; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "speex", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From 97a947ebad397381309c1c41badecc31999defb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:32:38 +0200 Subject: Rename audio_decoder.c and xine_decoder.c --HG-- rename : src/libreal/audio_decoder.c => src/libreal/xine_real_audio_decoder.c rename : src/libreal/xine_decoder.c => src/libreal/xine_real_video_decoder.c --- src/libreal/Makefile.am | 2 +- src/libreal/audio_decoder.c | 628 ---------------------------------- src/libreal/xine_decoder.c | 557 ------------------------------ src/libreal/xine_real_audio_decoder.c | 628 ++++++++++++++++++++++++++++++++++ src/libreal/xine_real_video_decoder.c | 557 ++++++++++++++++++++++++++++++ 5 files changed, 1186 insertions(+), 1186 deletions(-) delete mode 100644 src/libreal/audio_decoder.c delete mode 100644 src/libreal/xine_decoder.c create mode 100644 src/libreal/xine_real_audio_decoder.c create mode 100644 src/libreal/xine_real_video_decoder.c (limited to 'src') diff --git a/src/libreal/Makefile.am b/src/libreal/Makefile.am index 114a473a7..c9cf62984 100644 --- a/src/libreal/Makefile.am +++ b/src/libreal/Makefile.am @@ -4,7 +4,7 @@ if ENABLE_REAL xineplug_LTLIBRARIES = xineplug_decode_real.la endif -xineplug_decode_real_la_SOURCES = xine_decoder.c real_common.c audio_decoder.c +xineplug_decode_real_la_SOURCES = xine_real_video_decoder.c real_common.c xine_real_audio_decoder.c xineplug_decode_real_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) xineplug_decode_real_la_CFLAGS = $(VISIBILITY_FLAG) xineplug_decode_real_la_LDFLAGS = $(xineplug_ldflags) diff --git a/src/libreal/audio_decoder.c b/src/libreal/audio_decoder.c deleted file mode 100644 index d1bb94230..000000000 --- a/src/libreal/audio_decoder.c +++ /dev/null @@ -1,628 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: audio_decoder.c,v 1.59 2007/03/17 15:45:41 dgp85 Exp $ - * - * thin layer to use real binary-only codecs in xine - * - * code inspired by work from Florian Schneider for the MPlayer Project - */ - - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "real_audio_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "bswap.h" -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" - -#include "real_common.h" - -typedef struct { - audio_decoder_class_t decoder_class; - - /* empty so far */ -} real_class_t; - -typedef struct realdec_decoder_s { - audio_decoder_t audio_decoder; - - real_class_t *cls; - - xine_stream_t *stream; - - void *ra_handle; - - unsigned long (*raCloseCodec)(void*); - unsigned long (*raDecode)(void*, char*,unsigned long,char*,unsigned int*,long); - unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long); - unsigned long (*raFreeDecoder)(void*); - void* (*raGetFlavorProperty)(void*,unsigned long,unsigned long,int*); - unsigned long (*raInitDecoder)(void*, void*); - unsigned long (*raOpenCodec2)(void*); - unsigned long (*raSetFlavor)(void*,unsigned long); - void (*raSetDLLAccessPath)(char*); - void (*raSetPwd)(char*,char*); - - void *context; - - int sps, w, h; - int block_align; - - uint8_t *frame_buffer; - uint8_t *frame_reordered; - int frame_size; - int frame_num_bytes; - - int sample_size; - - uint64_t pts; - - int output_open; - - int decoder_ok; - -} realdec_decoder_t; - -typedef struct { - int samplerate; - short bits; - short channels; - int unk1; - int subpacket_size; - int coded_frame_size; - int codec_data_length; - void *extras; -} ra_init_t; - -static int load_syms_linux (realdec_decoder_t *this, const char *const codec_name, const char *const codec_alternate) { - cfg_entry_t* entry = - this->stream->xine->config->lookup_entry(this->stream->xine->config, - "decoder.external.real_codecs_path"); - - if ( (this->ra_handle = _x_real_codec_open(this->stream, entry->str_value, codec_name, codec_alternate)) == NULL ) - return 0; - - this->raCloseCodec = dlsym (this->ra_handle, "RACloseCodec"); - this->raDecode = dlsym (this->ra_handle, "RADecode"); - this->raFlush = dlsym (this->ra_handle, "RAFlush"); - this->raFreeDecoder = dlsym (this->ra_handle, "RAFreeDecoder"); - this->raGetFlavorProperty = dlsym (this->ra_handle, "RAGetFlavorProperty"); - this->raOpenCodec2 = dlsym (this->ra_handle, "RAOpenCodec2"); - this->raInitDecoder = dlsym (this->ra_handle, "RAInitDecoder"); - this->raSetFlavor = dlsym (this->ra_handle, "RASetFlavor"); - this->raSetDLLAccessPath = dlsym (this->ra_handle, "SetDLLAccessPath"); - this->raSetPwd = dlsym (this->ra_handle, "RASetPwd"); /* optional, used by SIPR */ - - if (!this->raCloseCodec || !this->raDecode || !this->raFlush || !this->raFreeDecoder || - !this->raGetFlavorProperty || !this->raOpenCodec2 || !this->raSetFlavor || - /*!raSetDLLAccessPath ||*/ !this->raInitDecoder){ - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("libareal: (audio) Cannot resolve symbols - incompatible dll: %s\n"), codec_name); - return 0; - } - - if (this->raSetDLLAccessPath){ - - char path[1024]; - - snprintf(path, sizeof(path) - 2, "DT_Codecs=%s", entry->str_value); - if (path[strlen(path)-1]!='/'){ - path[strlen(path)+1]=0; - path[strlen(path)]='/'; - } - path[strlen(path)+1]=0; - - this->raSetDLLAccessPath(path); - } - - lprintf ("audio decoder loaded successfully\n"); - - return 1; -} - -static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { - - int version, result ; - int samples_per_sec, bits_per_sample, num_channels; - int subpacket_size, coded_frame_size, codec_data_length; - int coded_frame_size2, data_len, flavor; - int mode; - void *extras; - - /* - * extract header data - */ - - version = BE_16 (buf->content+4); - - lprintf ("header buffer detected, header version %d\n", version); -#ifdef LOG - xine_hexdump (buf->content, buf->size); -#endif - - flavor = BE_16 (buf->content+22); - coded_frame_size = BE_32 (buf->content+24); - codec_data_length= BE_16 (buf->content+40); - coded_frame_size2= BE_16 (buf->content+42); - subpacket_size = BE_16 (buf->content+44); - - this->sps = subpacket_size; - this->w = coded_frame_size2; - this->h = codec_data_length; - - if (version == 4) { - samples_per_sec = BE_16 (buf->content+48); - bits_per_sample = BE_16 (buf->content+52); - num_channels = BE_16 (buf->content+54); - - /* FIXME: */ - if (buf->type==BUF_AUDIO_COOK) { - - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "libareal: audio header version 4 for COOK audio not supported.\n"); - return 0; - } - data_len = 0; /* FIXME: COOK audio needs this */ - extras = buf->content+71; - - } else { - samples_per_sec = BE_16 (buf->content+54); - bits_per_sample = BE_16 (buf->content+58); - num_channels = BE_16 (buf->content+60); - data_len = BE_32 (buf->content+74); - extras = buf->content+78; - } - - this->block_align= coded_frame_size2; - - lprintf ("0x%04x 0x%04x 0x%04x 0x%04x data_len 0x%04x\n", - subpacket_size, coded_frame_size, codec_data_length, - coded_frame_size2, data_len); - lprintf ("%d samples/sec, %d bits/sample, %d channels\n", - samples_per_sec, bits_per_sample, num_channels); - - /* load codec, resolv symbols */ - - switch (buf->type) { - case BUF_AUDIO_COOK: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Cook"); - if (!load_syms_linux (this, "cook.so", "cook.so.6.0")) - return 0; - break; - - case BUF_AUDIO_ATRK: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Atrac"); - if (!load_syms_linux (this, "atrc.so", "atrc.so.6.0")) - return 0; - this->block_align = 384; - break; - - case BUF_AUDIO_14_4: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Real 14.4"); - if (!load_syms_linux (this, "14_4.so", "14_4.so.6.0")) - return 0; - break; - - case BUF_AUDIO_28_8: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Real 28.8"); - if (!load_syms_linux (this, "28_8.so", "28_8.so.6.0")) - return 0; - break; - - case BUF_AUDIO_SIPRO: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Sipro"); - if (!load_syms_linux (this, "sipr.so", "sipr.so.6.0")) - return 0; - /* this->block_align = 19; */ - break; - - default: - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "libareal: error, i don't handle buf type 0x%08x\n", buf->type); - return 0; - } - - /* - * init codec - */ - - result = this->raOpenCodec2 (&this->context); - if (result) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libareal: error in raOpenCodec2: %d\n", result); - return 0; - } - - { - ra_init_t init_data; - - init_data.samplerate = samples_per_sec; - init_data.bits = bits_per_sample; - init_data.channels = num_channels; - init_data.unk1 = 100; /* ??? */ - init_data.subpacket_size = subpacket_size; /* subpacket size */ - init_data.coded_frame_size = coded_frame_size; /* coded frame size */ - init_data.codec_data_length = data_len; /* codec data length */ - init_data.extras = extras; /* extras */ - -#ifdef LOG - printf ("libareal: init_data:\n"); - xine_hexdump ((char *) &init_data, sizeof (ra_init_t)); - printf ("libareal: extras :\n"); - xine_hexdump (init_data.extras, data_len); -#endif - - result = this->raInitDecoder (this->context, &init_data); - if(result){ - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("libareal: decoder init failed, error code: 0x%x\n"), result); - return 0; - } - } - - if (this->raSetPwd){ - /* used by 'SIPR' */ - this->raSetPwd (this->context, "Ardubancel Quazanga"); /* set password... lol. */ - lprintf ("password set\n"); - } - - result = this->raSetFlavor (this->context, flavor); - if (result){ - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("libareal: decoder flavor setup failed, error code: 0x%x\n"), result); - return 0; - } - - /* - * alloc buffers for data reordering - */ - - if (this->sps) { - - this->frame_size = this->w/this->sps*this->h*this->sps; - this->frame_buffer = xine_xmalloc (this->frame_size); - this->frame_reordered = xine_xmalloc (this->frame_size); - this->frame_num_bytes = 0; - - } else { - - this->frame_size = this->w*this->h; - this->frame_buffer = xine_xmalloc (this->frame_size); - this->frame_reordered = this->frame_buffer; - this->frame_num_bytes = 0; - - } - - /* - * open audio output - */ - - switch (num_channels) { - case 1: - mode = AO_CAP_MODE_MONO; - break; - case 2: - mode = AO_CAP_MODE_STEREO; - break; - default: - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("libareal: oups, real can do more than 2 channels ?\n")); - return 0; - } - - this->stream->audio_out->open(this->stream->audio_out, - this->stream, - bits_per_sample, - samples_per_sec, - mode) ; - - this->output_open = 1; - - this->sample_size = num_channels * (bits_per_sample>>3); - - return 1; -} - -static unsigned char sipr_swaps[38][2]={ - {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, - {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, - {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, - {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, - {77,80} }; - -static void realdec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - lprintf ("decode_data %d bytes, flags=0x%08x, pts=%"PRId64" ...\n", - buf->size, buf->decoder_flags, buf->pts); - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - - /* real_find_sequence_header (&this->real, buf->content, buf->content + buf->size);*/ - - } else if (buf->decoder_flags & BUF_FLAG_HEADER) { - - this->decoder_ok = init_codec (this, buf) ; - if( !this->decoder_ok ) - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - - } else if( this->decoder_ok ) { - - int size; - - lprintf ("content buffer detected, %d bytes\n", buf->size); - - if (buf->pts && !this->pts) - this->pts = buf->pts; - - size = buf->size; - - while (size) { - - int needed; - - needed = this->frame_size - this->frame_num_bytes; - - if (needed>size) { - - memcpy (this->frame_buffer+this->frame_num_bytes, buf->content, size); - this->frame_num_bytes += size; - - lprintf ("buffering %d/%d bytes\n", this->frame_num_bytes, this->frame_size); - - size = 0; - - } else { - - int result; - int len =-1; - int n; - int sps = this->sps; - int w = this->w; - int h = this->h; - audio_buffer_t *audio_buffer; - - lprintf ("buffering %d bytes\n", needed); - - memcpy (this->frame_buffer+this->frame_num_bytes, buf->content, needed); - - size -= needed; - this->frame_num_bytes = 0; - - lprintf ("frame completed. reordering...\n"); - lprintf ("bs=%d sps=%d w=%d h=%d \n",/*sh->wf->nBlockAlign*/-1,sps,w,h); - - if (!sps) { - - int j,n; - int bs=h*w*2/96; /* nibbles per subpacket */ - unsigned char *p=this->frame_buffer; - - /* 'sipr' way */ - /* demux_read_data(sh->ds, p, h*w); */ - for (n=0;n<38;n++){ - int i=bs*sipr_swaps[n][0]; - int o=bs*sipr_swaps[n][1]; - /* swap nibbles of block 'i' with 'o' TODO: optimize */ - for (j=0;j>1)]>>4) : (p[(i>>1)]&15); - int y=(o&1) ? (p[(o>>1)]>>4) : (p[(o>>1)]&15); - if (o&1) - p[(o>>1)]=(p[(o>>1)]&0x0F)|(x<<4); - else - p[(o>>1)]=(p[(o>>1)]&0xF0)|x; - - if (i&1) - p[(i>>1)]=(p[(i>>1)]&0x0F)|(y<<4); - else - p[(i>>1)]=(p[(i>>1)]&0xF0)|y; - - ++i; - ++o; - } - } - /* - sh->a_in_buffer_size= - sh->a_in_buffer_len=w*h; - */ - - } else { - int x, y; - uint8_t *s; - - /* 'cook' way */ - - w /= sps; s = this->frame_buffer; - - for (y=0; y>1))); - - memcpy (this->frame_reordered+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), - s, sps); - s+=sps; - - /* demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), - sps); */ - - } - /* - sh->a_in_buffer_size= - sh->a_in_buffer_len=w*h*sps; - */ - } - -#ifdef LOG - xine_hexdump (this->frame_reordered, buf->size); -#endif - - n = 0; - while (nframe_size) { - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - result = this->raDecode (this->context, - this->frame_reordered+n, - this->block_align, - (char *) audio_buffer->mem, &len, -1); - - lprintf ("raDecode result %d, len=%d\n", result, len); - - audio_buffer->vpts = this->pts; - - this->pts = 0; - - audio_buffer->num_frames = len/this->sample_size;; - - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - n+=this->block_align; - } - } - } - } - - lprintf ("decode_data...done\n"); -} - -static void realdec_reset (audio_decoder_t *this_gen) { - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - this->frame_num_bytes = 0; -} - -static void realdec_discontinuity (audio_decoder_t *this_gen) { - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - this->pts = 0; -} - -static void realdec_dispose (audio_decoder_t *this_gen) { - - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - lprintf ("dispose\n"); - - if (this->context) - this->raCloseCodec (this->context); - -#if 0 - printf ("libareal: FreeDecoder...\n"); - - if (this->context) - this->raFreeDecoder (this->context); -#endif - - lprintf ("dlclose...\n"); - - if (this->ra_handle) - dlclose (this->ra_handle); - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - - if (this->frame_buffer) - free (this->frame_buffer); - - free (this); - - lprintf ("dispose done\n"); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, - xine_stream_t *stream) { - - real_class_t *cls = (real_class_t *) class_gen; - realdec_decoder_t *this ; - - this = (realdec_decoder_t *) xine_xmalloc (sizeof (realdec_decoder_t)); - - this->audio_decoder.decode_data = realdec_decode_data; - this->audio_decoder.reset = realdec_reset; - this->audio_decoder.discontinuity = realdec_discontinuity; - this->audio_decoder.dispose = realdec_dispose; - this->stream = stream; - this->cls = cls; - - this->output_open = 0; - - return &this->audio_decoder; -} - -/* - * real plugin class - */ - -static char *get_identifier (audio_decoder_class_t *this) { - return "realadec"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "real binary-only codec based audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -void *init_realadec (xine_t *xine, void *data) { - - real_class_t *this; - config_values_t *config = xine->config; - - this = (real_class_t *) xine_xmalloc (sizeof (real_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - _x_real_codecs_init(xine); - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t audio_types[] = { - BUF_AUDIO_COOK, BUF_AUDIO_ATRK, /* BUF_AUDIO_14_4, BUF_AUDIO_28_8, */ BUF_AUDIO_SIPRO, 0 - }; - -const decoder_info_t dec_info_realaudio = { - audio_types, /* supported types */ - 7 /* priority */ -}; diff --git a/src/libreal/xine_decoder.c b/src/libreal/xine_decoder.c deleted file mode 100644 index ea1fc8c54..000000000 --- a/src/libreal/xine_decoder.c +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (C) 2000-2004 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.93 2007/03/17 15:45:41 dgp85 Exp $ - * - * thin layer to use real binary-only codecs in xine - * - * code inspired by work from Florian Schneider for the MPlayer Project - */ - - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "real_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ -#include "bswap.h" -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" - -#include "real_common.h" - -typedef struct { - video_decoder_class_t decoder_class; - - /* empty so far */ -} real_class_t; - -#define BUF_SIZE 65536 - -typedef struct realdec_decoder_s { - video_decoder_t video_decoder; - - real_class_t *cls; - - xine_stream_t *stream; - - void *rv_handle; - - uint32_t (*rvyuv_custom_message)(void*, void*); - uint32_t (*rvyuv_free)(void*); - uint32_t (*rvyuv_hive_message)(uint32_t, uint32_t); - uint32_t (*rvyuv_init)(void*, void*); /* initdata,context */ - uint32_t (*rvyuv_transform)(char*, char*, void*, uint32_t*,void*); - - void *context; - - uint32_t width, height; - double ratio; - double fps; - - uint8_t *chunk_buffer; - int chunk_buffer_size; - int chunk_buffer_max; - - int64_t pts; - int duration; - - uint8_t *frame_buffer; - int frame_size; - int decoder_ok; - -} realdec_decoder_t; - -/* we need exact positions */ -typedef struct { - int16_t unk1; - int16_t w; - int16_t h; - int16_t unk3; - int32_t unk2; - int32_t subformat; - int32_t unk5; - int32_t format; -} rv_init_t; - -/* - * Structures for data packets. These used to be tables of unsigned ints, but - * that does not work on 64 bit platforms (e.g. Alpha). The entries that are - * pointers get truncated. Pointers on 64 bit platforms are 8 byte longs. - * So we have to use structures so the compiler will assign the proper space - * for the pointer. - */ -typedef struct cmsg_data_s { - uint32_t data1; - uint32_t data2; - uint32_t* dimensions; -} cmsg_data_t; - -typedef struct transform_in_s { - uint32_t len; - uint32_t unknown1; - uint32_t chunks; - uint32_t* extra; - uint32_t unknown2; - uint32_t timestamp; -} transform_in_t; - -/* - * real codec loader - */ - -static int load_syms_linux (realdec_decoder_t *this, const char *codec_name, const char *const codec_alternate) { - cfg_entry_t* entry = - this->stream->xine->config->lookup_entry(this->stream->xine->config, - "decoder.external.real_codecs_path"); - - if ( (this->rv_handle = _x_real_codec_open(this->stream, entry->str_value, codec_name, codec_alternate)) == NULL ) - return 0; - - this->rvyuv_custom_message = dlsym (this->rv_handle, "RV20toYUV420CustomMessage"); - this->rvyuv_free = dlsym (this->rv_handle, "RV20toYUV420Free"); - this->rvyuv_hive_message = dlsym (this->rv_handle, "RV20toYUV420HiveMessage"); - this->rvyuv_init = dlsym (this->rv_handle, "RV20toYUV420Init"); - this->rvyuv_transform = dlsym (this->rv_handle, "RV20toYUV420Transform"); - - if (this->rvyuv_custom_message && - this->rvyuv_free && - this->rvyuv_hive_message && - this->rvyuv_init && - this->rvyuv_transform) - return 1; - - this->rvyuv_custom_message = dlsym (this->rv_handle, "RV40toYUV420CustomMessage"); - this->rvyuv_free = dlsym (this->rv_handle, "RV40toYUV420Free"); - this->rvyuv_hive_message = dlsym (this->rv_handle, "RV40toYUV420HiveMessage"); - this->rvyuv_init = dlsym (this->rv_handle, "RV40toYUV420Init"); - this->rvyuv_transform = dlsym (this->rv_handle, "RV40toYUV420Transform"); - - if (this->rvyuv_custom_message && - this->rvyuv_free && - this->rvyuv_hive_message && - this->rvyuv_init && - this->rvyuv_transform) - return 1; - - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("libreal: Error resolving symbols! (version incompatibility?)\n")); - return 0; -} - -static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { - - /* unsigned int* extrahdr = (unsigned int*) (buf->content+28); */ - int result; - rv_init_t init_data = {11, 0, 0, 0, 0, 0, 1, 0}; /* rv30 */ - - - switch (buf->type) { - case BUF_VIDEO_RV20: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 2.0"); - if (!load_syms_linux (this, "drv2.so", "drv2.so.6.0")) - return 0; - break; - case BUF_VIDEO_RV30: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 3.0"); - if (!load_syms_linux (this, "drvc.so", "drv3.so.6.0")) - return 0; - break; - case BUF_VIDEO_RV40: - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 4.0"); - if (!load_syms_linux(this, "drvc.so", "drv3.so.6.0")) - return 0; - break; - default: - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "libreal: error, i don't handle buf type 0x%08x\n", buf->type); - _x_abort(); - } - - init_data.w = BE_16(&buf->content[12]); - init_data.h = BE_16(&buf->content[14]); - - this->width = (init_data.w + 1) & (~1); - this->height = (init_data.h + 1) & (~1); - - if(buf->decoder_flags & BUF_FLAG_ASPECT) - this->ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2]; - else - this->ratio = (double)this->width / (double)this->height; - - /* While the framerate is stored in the header it sometimes doesn't bear - * much resemblence to the actual frequency of frames in the file. Hence - * it's better to just let the engine estimate the frame duration for us */ -#if 0 - this->fps = (double) BE_16(&buf->content[22]) + - ((double) BE_16(&buf->content[24]) / 65536.0); - this->duration = 90000.0 / this->fps; -#endif - - lprintf("this->ratio=%f\n", this->ratio); - - lprintf ("init_data.w=%d(0x%x), init_data.h=%d(0x%x)," - "this->width=%d(0x%x), this->height=%d(0x%x)\n", - init_data.w, init_data.w, - init_data.h, init_data.h, - this->width, this->width, this->height, this->height); - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->width); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->height); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, this->ratio*10000); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->duration); - - init_data.subformat = BE_32(&buf->content[26]); - init_data.format = BE_32(&buf->content[30]); - -#ifdef LOG - printf ("libreal: init_data for rvyuv_init:\n"); - xine_hexdump ((char *) &init_data, sizeof (init_data)); - - printf ("libreal: buf->content\n"); - xine_hexdump (buf->content, buf->size); -#endif - lprintf ("init codec %dx%d... %x %x\n", - init_data.w, init_data.h, - init_data.subformat, init_data.format ); - - this->context = NULL; - - result = this->rvyuv_init (&init_data, &this->context); - - lprintf ("init result: %d\n", result); - - /* setup rv30 codec (codec sub-type and image dimensions): */ - if ((init_data.format>=0x20200002) && (buf->type != BUF_VIDEO_RV40)) { - int i, j; - uint32_t cmsg24[(buf->size - 34 + 2) * sizeof(uint32_t)]; - cmsg_data_t cmsg_data = { 0x24, 1 + ((init_data.subformat >> 16) & 7), &cmsg24[0] }; - - cmsg24[0] = this->width; - cmsg24[1] = this->height; - for(i = 2, j = 34; j < buf->size; i++, j++) - cmsg24[i] = 4 * buf->content[j]; - -#ifdef LOG - printf ("libreal: CustomMessage cmsg_data:\n"); - xine_hexdump ((uint8_t *) cmsg_data, sizeof (cmsg_data)); - printf ("libreal: cmsg24:\n"); - xine_hexdump ((uint8_t *) cmsg24, (buf->size - 34 + 2) * sizeof(uint32_t)); -#endif - - this->rvyuv_custom_message (&cmsg_data, this->context); - } - - this->stream->video_out->open(this->stream->video_out, this->stream); - - this->frame_size = this->width * this->height; - this->frame_buffer = xine_xmalloc (this->width * this->height * 3 / 2); - - this->chunk_buffer = xine_xmalloc (BUF_SIZE); - this->chunk_buffer_max = BUF_SIZE; - - return 1; -} - -static void realdec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - lprintf ("decode_data, flags=0x%08x, len=%d, pts=%"PRId64" ...\n", - buf->decoder_flags, buf->size, buf->pts); - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - /* real_find_sequence_header (&this->real, buf->content, buf->content + buf->size);*/ - return; - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->duration = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, - this->duration); - } - - if (buf->decoder_flags & BUF_FLAG_HEADER) { - - this->decoder_ok = init_codec (this, buf); - if( !this->decoder_ok ) - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); - - } else if (this->decoder_ok && this->context) { - - /* Each frame starts with BUF_FLAG_FRAME_START and ends with - * BUF_FLAG_FRAME_END. - * The last buffer contains the chunk offset table. - */ - - if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { - - lprintf ("buffer (%d bytes)\n", buf->size); - - if (buf->decoder_flags & BUF_FLAG_FRAME_START) { - /* new frame starting */ - - this->chunk_buffer_size = 0; - this->pts = buf->pts; - lprintf ("new frame starting, pts=%"PRId64"\n", this->pts); - } - - if ((this->chunk_buffer_size + buf->size) > this->chunk_buffer_max) { - lprintf("increasing chunk buffer size\n"); - - this->chunk_buffer_max *= 2; - this->chunk_buffer = realloc(this->chunk_buffer, this->chunk_buffer_max); - } - - xine_fast_memcpy (this->chunk_buffer + this->chunk_buffer_size, - buf->content, - buf->size); - - this->chunk_buffer_size += buf->size; - - } else { - /* end of frame, chunk table */ - - lprintf ("special buffer (%d bytes)\n", buf->size); - - if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) { - - int result; - vo_frame_t *img; - - uint32_t transform_out[5]; - transform_in_t transform_in = { - this->chunk_buffer_size, - /* length of the packet (sub-packets appended) */ - 0, - /* unknown, seems to be unused */ - buf->decoder_info[2], - /* number of sub-packets - 1 */ - buf->decoder_info_ptr[2], - /* table of sub-packet offsets */ - 0, - /* unknown, seems to be unused */ - this->pts / 90 - /* timestamp (the integer value from the stream) */ - }; - - lprintf ("chunk table\n"); - - -#ifdef LOG - printf ("libreal: got %d chunks\n", - buf->decoder_info[2] + 1); - - printf ("libreal: decoding %d bytes:\n", this->chunk_buffer_size); - xine_hexdump (this->chunk_buffer, this->chunk_buffer_size); - - printf ("libreal: transform_in:\n"); - xine_hexdump ((uint8_t *) transform_in, 6 * 4); - - printf ("libreal: chunk_table:\n"); - xine_hexdump ((uint8_t *) buf->decoder_info_ptr[2], - 2*(buf->decoder_info[2]+1)*sizeof(uint32_t)); -#endif - - result = this->rvyuv_transform (this->chunk_buffer, - this->frame_buffer, - &transform_in, - transform_out, - this->context); - - lprintf ("transform result: %08x\n", result); - lprintf ("transform_out:\n"); - #ifdef LOG - xine_hexdump ((uint8_t *) transform_out, 5 * 4); - #endif - - /* Sometimes the stream contains video of a different size - * to that specified in the realmedia header */ - if(transform_out[0] && ((transform_out[3] != this->width) || - (transform_out[4] != this->height))) { - this->width = transform_out[3]; - this->height = transform_out[4]; - - this->frame_size = this->width * this->height; - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->width); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->height); - } - - img = this->stream->video_out->get_frame (this->stream->video_out, - /* this->av_picture.linesize[0], */ - this->width, - this->height, - this->ratio, - XINE_IMGFMT_YV12, - VO_BOTH_FIELDS); - - img->pts = this->pts; - img->duration = this->duration; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->duration); - img->bad_frame = 0; - - yv12_to_yv12( - /* Y */ - this->frame_buffer, this->width, - img->base[0], img->pitches[0], - /* U */ - this->frame_buffer + this->frame_size, this->width/2, - img->base[1], img->pitches[1], - /* V */ - this->frame_buffer + this->frame_size * 5/4, this->width/2, - img->base[2], img->pitches[2], - /* width x height */ - this->width, this->height); - - img->draw(img, this->stream); - img->free(img); - - } else { - /* unsupported special buf */ - } - } - } - - lprintf ("decode_data...done\n"); -} - -static void realdec_flush (video_decoder_t *this_gen) { - /* realdec_decoder_t *this = (realdec_decoder_t *) this_gen; */ - - lprintf ("flush\n"); -} - -static void realdec_reset (video_decoder_t *this_gen) { - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - this->chunk_buffer_size = 0; -} - -static void realdec_discontinuity (video_decoder_t *this_gen) { - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - this->pts = 0; -} - -static void realdec_dispose (video_decoder_t *this_gen) { - - realdec_decoder_t *this = (realdec_decoder_t *) this_gen; - - lprintf ("dispose\n"); - - if (this->context) - this->stream->video_out->close(this->stream->video_out, this->stream); - - if (this->rvyuv_free && this->context) - this->rvyuv_free (this->context); - - if (this->rv_handle) - dlclose (this->rv_handle); - - if (this->frame_buffer) - free (this->frame_buffer); - - if (this->chunk_buffer) - free (this->chunk_buffer); - - free (this); - - lprintf ("dispose done\n"); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, - xine_stream_t *stream) { - - real_class_t *cls = (real_class_t *) class_gen; - realdec_decoder_t *this ; - - this = (realdec_decoder_t *) xine_xmalloc (sizeof (realdec_decoder_t)); - - this->video_decoder.decode_data = realdec_decode_data; - this->video_decoder.flush = realdec_flush; - this->video_decoder.reset = realdec_reset; - this->video_decoder.discontinuity = realdec_discontinuity; - this->video_decoder.dispose = realdec_dispose; - this->stream = stream; - this->cls = cls; - - this->context = 0; - this->pts = 0; - - this->duration = 0; - - return &this->video_decoder; -} - -/* - * real plugin class - */ - -static char *get_identifier (video_decoder_class_t *this) { - return "realvdec"; -} - -static char *get_description (video_decoder_class_t *this) { - return "real binary-only codec based video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -void *init_realvdec (xine_t *xine, void *data) { - - real_class_t *this; - config_values_t *config = xine->config; - - this = (real_class_t *) xine_xmalloc (sizeof (real_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - _x_real_codecs_init(xine); - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t supported_types[] = { BUF_VIDEO_RV20, - BUF_VIDEO_RV30, - BUF_VIDEO_RV40, - 0 }; - -const decoder_info_t dec_info_realvideo = { - supported_types, /* supported types */ - 7 /* priority */ -}; diff --git a/src/libreal/xine_real_audio_decoder.c b/src/libreal/xine_real_audio_decoder.c new file mode 100644 index 000000000..d1bb94230 --- /dev/null +++ b/src/libreal/xine_real_audio_decoder.c @@ -0,0 +1,628 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: audio_decoder.c,v 1.59 2007/03/17 15:45:41 dgp85 Exp $ + * + * thin layer to use real binary-only codecs in xine + * + * code inspired by work from Florian Schneider for the MPlayer Project + */ + + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "real_audio_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "bswap.h" +#include "xine_internal.h" +#include "video_out.h" +#include "buffer.h" +#include "xineutils.h" + +#include "real_common.h" + +typedef struct { + audio_decoder_class_t decoder_class; + + /* empty so far */ +} real_class_t; + +typedef struct realdec_decoder_s { + audio_decoder_t audio_decoder; + + real_class_t *cls; + + xine_stream_t *stream; + + void *ra_handle; + + unsigned long (*raCloseCodec)(void*); + unsigned long (*raDecode)(void*, char*,unsigned long,char*,unsigned int*,long); + unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long); + unsigned long (*raFreeDecoder)(void*); + void* (*raGetFlavorProperty)(void*,unsigned long,unsigned long,int*); + unsigned long (*raInitDecoder)(void*, void*); + unsigned long (*raOpenCodec2)(void*); + unsigned long (*raSetFlavor)(void*,unsigned long); + void (*raSetDLLAccessPath)(char*); + void (*raSetPwd)(char*,char*); + + void *context; + + int sps, w, h; + int block_align; + + uint8_t *frame_buffer; + uint8_t *frame_reordered; + int frame_size; + int frame_num_bytes; + + int sample_size; + + uint64_t pts; + + int output_open; + + int decoder_ok; + +} realdec_decoder_t; + +typedef struct { + int samplerate; + short bits; + short channels; + int unk1; + int subpacket_size; + int coded_frame_size; + int codec_data_length; + void *extras; +} ra_init_t; + +static int load_syms_linux (realdec_decoder_t *this, const char *const codec_name, const char *const codec_alternate) { + cfg_entry_t* entry = + this->stream->xine->config->lookup_entry(this->stream->xine->config, + "decoder.external.real_codecs_path"); + + if ( (this->ra_handle = _x_real_codec_open(this->stream, entry->str_value, codec_name, codec_alternate)) == NULL ) + return 0; + + this->raCloseCodec = dlsym (this->ra_handle, "RACloseCodec"); + this->raDecode = dlsym (this->ra_handle, "RADecode"); + this->raFlush = dlsym (this->ra_handle, "RAFlush"); + this->raFreeDecoder = dlsym (this->ra_handle, "RAFreeDecoder"); + this->raGetFlavorProperty = dlsym (this->ra_handle, "RAGetFlavorProperty"); + this->raOpenCodec2 = dlsym (this->ra_handle, "RAOpenCodec2"); + this->raInitDecoder = dlsym (this->ra_handle, "RAInitDecoder"); + this->raSetFlavor = dlsym (this->ra_handle, "RASetFlavor"); + this->raSetDLLAccessPath = dlsym (this->ra_handle, "SetDLLAccessPath"); + this->raSetPwd = dlsym (this->ra_handle, "RASetPwd"); /* optional, used by SIPR */ + + if (!this->raCloseCodec || !this->raDecode || !this->raFlush || !this->raFreeDecoder || + !this->raGetFlavorProperty || !this->raOpenCodec2 || !this->raSetFlavor || + /*!raSetDLLAccessPath ||*/ !this->raInitDecoder){ + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("libareal: (audio) Cannot resolve symbols - incompatible dll: %s\n"), codec_name); + return 0; + } + + if (this->raSetDLLAccessPath){ + + char path[1024]; + + snprintf(path, sizeof(path) - 2, "DT_Codecs=%s", entry->str_value); + if (path[strlen(path)-1]!='/'){ + path[strlen(path)+1]=0; + path[strlen(path)]='/'; + } + path[strlen(path)+1]=0; + + this->raSetDLLAccessPath(path); + } + + lprintf ("audio decoder loaded successfully\n"); + + return 1; +} + +static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { + + int version, result ; + int samples_per_sec, bits_per_sample, num_channels; + int subpacket_size, coded_frame_size, codec_data_length; + int coded_frame_size2, data_len, flavor; + int mode; + void *extras; + + /* + * extract header data + */ + + version = BE_16 (buf->content+4); + + lprintf ("header buffer detected, header version %d\n", version); +#ifdef LOG + xine_hexdump (buf->content, buf->size); +#endif + + flavor = BE_16 (buf->content+22); + coded_frame_size = BE_32 (buf->content+24); + codec_data_length= BE_16 (buf->content+40); + coded_frame_size2= BE_16 (buf->content+42); + subpacket_size = BE_16 (buf->content+44); + + this->sps = subpacket_size; + this->w = coded_frame_size2; + this->h = codec_data_length; + + if (version == 4) { + samples_per_sec = BE_16 (buf->content+48); + bits_per_sample = BE_16 (buf->content+52); + num_channels = BE_16 (buf->content+54); + + /* FIXME: */ + if (buf->type==BUF_AUDIO_COOK) { + + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "libareal: audio header version 4 for COOK audio not supported.\n"); + return 0; + } + data_len = 0; /* FIXME: COOK audio needs this */ + extras = buf->content+71; + + } else { + samples_per_sec = BE_16 (buf->content+54); + bits_per_sample = BE_16 (buf->content+58); + num_channels = BE_16 (buf->content+60); + data_len = BE_32 (buf->content+74); + extras = buf->content+78; + } + + this->block_align= coded_frame_size2; + + lprintf ("0x%04x 0x%04x 0x%04x 0x%04x data_len 0x%04x\n", + subpacket_size, coded_frame_size, codec_data_length, + coded_frame_size2, data_len); + lprintf ("%d samples/sec, %d bits/sample, %d channels\n", + samples_per_sec, bits_per_sample, num_channels); + + /* load codec, resolv symbols */ + + switch (buf->type) { + case BUF_AUDIO_COOK: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Cook"); + if (!load_syms_linux (this, "cook.so", "cook.so.6.0")) + return 0; + break; + + case BUF_AUDIO_ATRK: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Atrac"); + if (!load_syms_linux (this, "atrc.so", "atrc.so.6.0")) + return 0; + this->block_align = 384; + break; + + case BUF_AUDIO_14_4: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Real 14.4"); + if (!load_syms_linux (this, "14_4.so", "14_4.so.6.0")) + return 0; + break; + + case BUF_AUDIO_28_8: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Real 28.8"); + if (!load_syms_linux (this, "28_8.so", "28_8.so.6.0")) + return 0; + break; + + case BUF_AUDIO_SIPRO: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Sipro"); + if (!load_syms_linux (this, "sipr.so", "sipr.so.6.0")) + return 0; + /* this->block_align = 19; */ + break; + + default: + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "libareal: error, i don't handle buf type 0x%08x\n", buf->type); + return 0; + } + + /* + * init codec + */ + + result = this->raOpenCodec2 (&this->context); + if (result) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libareal: error in raOpenCodec2: %d\n", result); + return 0; + } + + { + ra_init_t init_data; + + init_data.samplerate = samples_per_sec; + init_data.bits = bits_per_sample; + init_data.channels = num_channels; + init_data.unk1 = 100; /* ??? */ + init_data.subpacket_size = subpacket_size; /* subpacket size */ + init_data.coded_frame_size = coded_frame_size; /* coded frame size */ + init_data.codec_data_length = data_len; /* codec data length */ + init_data.extras = extras; /* extras */ + +#ifdef LOG + printf ("libareal: init_data:\n"); + xine_hexdump ((char *) &init_data, sizeof (ra_init_t)); + printf ("libareal: extras :\n"); + xine_hexdump (init_data.extras, data_len); +#endif + + result = this->raInitDecoder (this->context, &init_data); + if(result){ + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("libareal: decoder init failed, error code: 0x%x\n"), result); + return 0; + } + } + + if (this->raSetPwd){ + /* used by 'SIPR' */ + this->raSetPwd (this->context, "Ardubancel Quazanga"); /* set password... lol. */ + lprintf ("password set\n"); + } + + result = this->raSetFlavor (this->context, flavor); + if (result){ + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("libareal: decoder flavor setup failed, error code: 0x%x\n"), result); + return 0; + } + + /* + * alloc buffers for data reordering + */ + + if (this->sps) { + + this->frame_size = this->w/this->sps*this->h*this->sps; + this->frame_buffer = xine_xmalloc (this->frame_size); + this->frame_reordered = xine_xmalloc (this->frame_size); + this->frame_num_bytes = 0; + + } else { + + this->frame_size = this->w*this->h; + this->frame_buffer = xine_xmalloc (this->frame_size); + this->frame_reordered = this->frame_buffer; + this->frame_num_bytes = 0; + + } + + /* + * open audio output + */ + + switch (num_channels) { + case 1: + mode = AO_CAP_MODE_MONO; + break; + case 2: + mode = AO_CAP_MODE_STEREO; + break; + default: + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("libareal: oups, real can do more than 2 channels ?\n")); + return 0; + } + + this->stream->audio_out->open(this->stream->audio_out, + this->stream, + bits_per_sample, + samples_per_sec, + mode) ; + + this->output_open = 1; + + this->sample_size = num_channels * (bits_per_sample>>3); + + return 1; +} + +static unsigned char sipr_swaps[38][2]={ + {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, + {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, + {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, + {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, + {77,80} }; + +static void realdec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + lprintf ("decode_data %d bytes, flags=0x%08x, pts=%"PRId64" ...\n", + buf->size, buf->decoder_flags, buf->pts); + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) { + + /* real_find_sequence_header (&this->real, buf->content, buf->content + buf->size);*/ + + } else if (buf->decoder_flags & BUF_FLAG_HEADER) { + + this->decoder_ok = init_codec (this, buf) ; + if( !this->decoder_ok ) + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + + } else if( this->decoder_ok ) { + + int size; + + lprintf ("content buffer detected, %d bytes\n", buf->size); + + if (buf->pts && !this->pts) + this->pts = buf->pts; + + size = buf->size; + + while (size) { + + int needed; + + needed = this->frame_size - this->frame_num_bytes; + + if (needed>size) { + + memcpy (this->frame_buffer+this->frame_num_bytes, buf->content, size); + this->frame_num_bytes += size; + + lprintf ("buffering %d/%d bytes\n", this->frame_num_bytes, this->frame_size); + + size = 0; + + } else { + + int result; + int len =-1; + int n; + int sps = this->sps; + int w = this->w; + int h = this->h; + audio_buffer_t *audio_buffer; + + lprintf ("buffering %d bytes\n", needed); + + memcpy (this->frame_buffer+this->frame_num_bytes, buf->content, needed); + + size -= needed; + this->frame_num_bytes = 0; + + lprintf ("frame completed. reordering...\n"); + lprintf ("bs=%d sps=%d w=%d h=%d \n",/*sh->wf->nBlockAlign*/-1,sps,w,h); + + if (!sps) { + + int j,n; + int bs=h*w*2/96; /* nibbles per subpacket */ + unsigned char *p=this->frame_buffer; + + /* 'sipr' way */ + /* demux_read_data(sh->ds, p, h*w); */ + for (n=0;n<38;n++){ + int i=bs*sipr_swaps[n][0]; + int o=bs*sipr_swaps[n][1]; + /* swap nibbles of block 'i' with 'o' TODO: optimize */ + for (j=0;j>1)]>>4) : (p[(i>>1)]&15); + int y=(o&1) ? (p[(o>>1)]>>4) : (p[(o>>1)]&15); + if (o&1) + p[(o>>1)]=(p[(o>>1)]&0x0F)|(x<<4); + else + p[(o>>1)]=(p[(o>>1)]&0xF0)|x; + + if (i&1) + p[(i>>1)]=(p[(i>>1)]&0x0F)|(y<<4); + else + p[(i>>1)]=(p[(i>>1)]&0xF0)|y; + + ++i; + ++o; + } + } + /* + sh->a_in_buffer_size= + sh->a_in_buffer_len=w*h; + */ + + } else { + int x, y; + uint8_t *s; + + /* 'cook' way */ + + w /= sps; s = this->frame_buffer; + + for (y=0; y>1))); + + memcpy (this->frame_reordered+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), + s, sps); + s+=sps; + + /* demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), + sps); */ + + } + /* + sh->a_in_buffer_size= + sh->a_in_buffer_len=w*h*sps; + */ + } + +#ifdef LOG + xine_hexdump (this->frame_reordered, buf->size); +#endif + + n = 0; + while (nframe_size) { + + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + + result = this->raDecode (this->context, + this->frame_reordered+n, + this->block_align, + (char *) audio_buffer->mem, &len, -1); + + lprintf ("raDecode result %d, len=%d\n", result, len); + + audio_buffer->vpts = this->pts; + + this->pts = 0; + + audio_buffer->num_frames = len/this->sample_size;; + + this->stream->audio_out->put_buffer (this->stream->audio_out, + audio_buffer, this->stream); + n+=this->block_align; + } + } + } + } + + lprintf ("decode_data...done\n"); +} + +static void realdec_reset (audio_decoder_t *this_gen) { + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + this->frame_num_bytes = 0; +} + +static void realdec_discontinuity (audio_decoder_t *this_gen) { + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + this->pts = 0; +} + +static void realdec_dispose (audio_decoder_t *this_gen) { + + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + lprintf ("dispose\n"); + + if (this->context) + this->raCloseCodec (this->context); + +#if 0 + printf ("libareal: FreeDecoder...\n"); + + if (this->context) + this->raFreeDecoder (this->context); +#endif + + lprintf ("dlclose...\n"); + + if (this->ra_handle) + dlclose (this->ra_handle); + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + + if (this->frame_buffer) + free (this->frame_buffer); + + free (this); + + lprintf ("dispose done\n"); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, + xine_stream_t *stream) { + + real_class_t *cls = (real_class_t *) class_gen; + realdec_decoder_t *this ; + + this = (realdec_decoder_t *) xine_xmalloc (sizeof (realdec_decoder_t)); + + this->audio_decoder.decode_data = realdec_decode_data; + this->audio_decoder.reset = realdec_reset; + this->audio_decoder.discontinuity = realdec_discontinuity; + this->audio_decoder.dispose = realdec_dispose; + this->stream = stream; + this->cls = cls; + + this->output_open = 0; + + return &this->audio_decoder; +} + +/* + * real plugin class + */ + +static char *get_identifier (audio_decoder_class_t *this) { + return "realadec"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "real binary-only codec based audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this) { + free (this); +} + +void *init_realadec (xine_t *xine, void *data) { + + real_class_t *this; + config_values_t *config = xine->config; + + this = (real_class_t *) xine_xmalloc (sizeof (real_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + _x_real_codecs_init(xine); + + return this; +} + +/* + * exported plugin catalog entry + */ + +static uint32_t audio_types[] = { + BUF_AUDIO_COOK, BUF_AUDIO_ATRK, /* BUF_AUDIO_14_4, BUF_AUDIO_28_8, */ BUF_AUDIO_SIPRO, 0 + }; + +const decoder_info_t dec_info_realaudio = { + audio_types, /* supported types */ + 7 /* priority */ +}; diff --git a/src/libreal/xine_real_video_decoder.c b/src/libreal/xine_real_video_decoder.c new file mode 100644 index 000000000..ea1fc8c54 --- /dev/null +++ b/src/libreal/xine_real_video_decoder.c @@ -0,0 +1,557 @@ +/* + * Copyright (C) 2000-2004 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.93 2007/03/17 15:45:41 dgp85 Exp $ + * + * thin layer to use real binary-only codecs in xine + * + * code inspired by work from Florian Schneider for the MPlayer Project + */ + + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "real_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ +#include "bswap.h" +#include "xine_internal.h" +#include "video_out.h" +#include "buffer.h" +#include "xineutils.h" + +#include "real_common.h" + +typedef struct { + video_decoder_class_t decoder_class; + + /* empty so far */ +} real_class_t; + +#define BUF_SIZE 65536 + +typedef struct realdec_decoder_s { + video_decoder_t video_decoder; + + real_class_t *cls; + + xine_stream_t *stream; + + void *rv_handle; + + uint32_t (*rvyuv_custom_message)(void*, void*); + uint32_t (*rvyuv_free)(void*); + uint32_t (*rvyuv_hive_message)(uint32_t, uint32_t); + uint32_t (*rvyuv_init)(void*, void*); /* initdata,context */ + uint32_t (*rvyuv_transform)(char*, char*, void*, uint32_t*,void*); + + void *context; + + uint32_t width, height; + double ratio; + double fps; + + uint8_t *chunk_buffer; + int chunk_buffer_size; + int chunk_buffer_max; + + int64_t pts; + int duration; + + uint8_t *frame_buffer; + int frame_size; + int decoder_ok; + +} realdec_decoder_t; + +/* we need exact positions */ +typedef struct { + int16_t unk1; + int16_t w; + int16_t h; + int16_t unk3; + int32_t unk2; + int32_t subformat; + int32_t unk5; + int32_t format; +} rv_init_t; + +/* + * Structures for data packets. These used to be tables of unsigned ints, but + * that does not work on 64 bit platforms (e.g. Alpha). The entries that are + * pointers get truncated. Pointers on 64 bit platforms are 8 byte longs. + * So we have to use structures so the compiler will assign the proper space + * for the pointer. + */ +typedef struct cmsg_data_s { + uint32_t data1; + uint32_t data2; + uint32_t* dimensions; +} cmsg_data_t; + +typedef struct transform_in_s { + uint32_t len; + uint32_t unknown1; + uint32_t chunks; + uint32_t* extra; + uint32_t unknown2; + uint32_t timestamp; +} transform_in_t; + +/* + * real codec loader + */ + +static int load_syms_linux (realdec_decoder_t *this, const char *codec_name, const char *const codec_alternate) { + cfg_entry_t* entry = + this->stream->xine->config->lookup_entry(this->stream->xine->config, + "decoder.external.real_codecs_path"); + + if ( (this->rv_handle = _x_real_codec_open(this->stream, entry->str_value, codec_name, codec_alternate)) == NULL ) + return 0; + + this->rvyuv_custom_message = dlsym (this->rv_handle, "RV20toYUV420CustomMessage"); + this->rvyuv_free = dlsym (this->rv_handle, "RV20toYUV420Free"); + this->rvyuv_hive_message = dlsym (this->rv_handle, "RV20toYUV420HiveMessage"); + this->rvyuv_init = dlsym (this->rv_handle, "RV20toYUV420Init"); + this->rvyuv_transform = dlsym (this->rv_handle, "RV20toYUV420Transform"); + + if (this->rvyuv_custom_message && + this->rvyuv_free && + this->rvyuv_hive_message && + this->rvyuv_init && + this->rvyuv_transform) + return 1; + + this->rvyuv_custom_message = dlsym (this->rv_handle, "RV40toYUV420CustomMessage"); + this->rvyuv_free = dlsym (this->rv_handle, "RV40toYUV420Free"); + this->rvyuv_hive_message = dlsym (this->rv_handle, "RV40toYUV420HiveMessage"); + this->rvyuv_init = dlsym (this->rv_handle, "RV40toYUV420Init"); + this->rvyuv_transform = dlsym (this->rv_handle, "RV40toYUV420Transform"); + + if (this->rvyuv_custom_message && + this->rvyuv_free && + this->rvyuv_hive_message && + this->rvyuv_init && + this->rvyuv_transform) + return 1; + + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("libreal: Error resolving symbols! (version incompatibility?)\n")); + return 0; +} + +static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { + + /* unsigned int* extrahdr = (unsigned int*) (buf->content+28); */ + int result; + rv_init_t init_data = {11, 0, 0, 0, 0, 0, 1, 0}; /* rv30 */ + + + switch (buf->type) { + case BUF_VIDEO_RV20: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 2.0"); + if (!load_syms_linux (this, "drv2.so", "drv2.so.6.0")) + return 0; + break; + case BUF_VIDEO_RV30: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 3.0"); + if (!load_syms_linux (this, "drvc.so", "drv3.so.6.0")) + return 0; + break; + case BUF_VIDEO_RV40: + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 4.0"); + if (!load_syms_linux(this, "drvc.so", "drv3.so.6.0")) + return 0; + break; + default: + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "libreal: error, i don't handle buf type 0x%08x\n", buf->type); + _x_abort(); + } + + init_data.w = BE_16(&buf->content[12]); + init_data.h = BE_16(&buf->content[14]); + + this->width = (init_data.w + 1) & (~1); + this->height = (init_data.h + 1) & (~1); + + if(buf->decoder_flags & BUF_FLAG_ASPECT) + this->ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2]; + else + this->ratio = (double)this->width / (double)this->height; + + /* While the framerate is stored in the header it sometimes doesn't bear + * much resemblence to the actual frequency of frames in the file. Hence + * it's better to just let the engine estimate the frame duration for us */ +#if 0 + this->fps = (double) BE_16(&buf->content[22]) + + ((double) BE_16(&buf->content[24]) / 65536.0); + this->duration = 90000.0 / this->fps; +#endif + + lprintf("this->ratio=%f\n", this->ratio); + + lprintf ("init_data.w=%d(0x%x), init_data.h=%d(0x%x)," + "this->width=%d(0x%x), this->height=%d(0x%x)\n", + init_data.w, init_data.w, + init_data.h, init_data.h, + this->width, this->width, this->height, this->height); + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->width); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->height); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, this->ratio*10000); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->duration); + + init_data.subformat = BE_32(&buf->content[26]); + init_data.format = BE_32(&buf->content[30]); + +#ifdef LOG + printf ("libreal: init_data for rvyuv_init:\n"); + xine_hexdump ((char *) &init_data, sizeof (init_data)); + + printf ("libreal: buf->content\n"); + xine_hexdump (buf->content, buf->size); +#endif + lprintf ("init codec %dx%d... %x %x\n", + init_data.w, init_data.h, + init_data.subformat, init_data.format ); + + this->context = NULL; + + result = this->rvyuv_init (&init_data, &this->context); + + lprintf ("init result: %d\n", result); + + /* setup rv30 codec (codec sub-type and image dimensions): */ + if ((init_data.format>=0x20200002) && (buf->type != BUF_VIDEO_RV40)) { + int i, j; + uint32_t cmsg24[(buf->size - 34 + 2) * sizeof(uint32_t)]; + cmsg_data_t cmsg_data = { 0x24, 1 + ((init_data.subformat >> 16) & 7), &cmsg24[0] }; + + cmsg24[0] = this->width; + cmsg24[1] = this->height; + for(i = 2, j = 34; j < buf->size; i++, j++) + cmsg24[i] = 4 * buf->content[j]; + +#ifdef LOG + printf ("libreal: CustomMessage cmsg_data:\n"); + xine_hexdump ((uint8_t *) cmsg_data, sizeof (cmsg_data)); + printf ("libreal: cmsg24:\n"); + xine_hexdump ((uint8_t *) cmsg24, (buf->size - 34 + 2) * sizeof(uint32_t)); +#endif + + this->rvyuv_custom_message (&cmsg_data, this->context); + } + + this->stream->video_out->open(this->stream->video_out, this->stream); + + this->frame_size = this->width * this->height; + this->frame_buffer = xine_xmalloc (this->width * this->height * 3 / 2); + + this->chunk_buffer = xine_xmalloc (BUF_SIZE); + this->chunk_buffer_max = BUF_SIZE; + + return 1; +} + +static void realdec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + lprintf ("decode_data, flags=0x%08x, len=%d, pts=%"PRId64" ...\n", + buf->decoder_flags, buf->size, buf->pts); + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) { + /* real_find_sequence_header (&this->real, buf->content, buf->content + buf->size);*/ + return; + } + + if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { + this->duration = buf->decoder_info[0]; + _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, + this->duration); + } + + if (buf->decoder_flags & BUF_FLAG_HEADER) { + + this->decoder_ok = init_codec (this, buf); + if( !this->decoder_ok ) + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); + + } else if (this->decoder_ok && this->context) { + + /* Each frame starts with BUF_FLAG_FRAME_START and ends with + * BUF_FLAG_FRAME_END. + * The last buffer contains the chunk offset table. + */ + + if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { + + lprintf ("buffer (%d bytes)\n", buf->size); + + if (buf->decoder_flags & BUF_FLAG_FRAME_START) { + /* new frame starting */ + + this->chunk_buffer_size = 0; + this->pts = buf->pts; + lprintf ("new frame starting, pts=%"PRId64"\n", this->pts); + } + + if ((this->chunk_buffer_size + buf->size) > this->chunk_buffer_max) { + lprintf("increasing chunk buffer size\n"); + + this->chunk_buffer_max *= 2; + this->chunk_buffer = realloc(this->chunk_buffer, this->chunk_buffer_max); + } + + xine_fast_memcpy (this->chunk_buffer + this->chunk_buffer_size, + buf->content, + buf->size); + + this->chunk_buffer_size += buf->size; + + } else { + /* end of frame, chunk table */ + + lprintf ("special buffer (%d bytes)\n", buf->size); + + if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) { + + int result; + vo_frame_t *img; + + uint32_t transform_out[5]; + transform_in_t transform_in = { + this->chunk_buffer_size, + /* length of the packet (sub-packets appended) */ + 0, + /* unknown, seems to be unused */ + buf->decoder_info[2], + /* number of sub-packets - 1 */ + buf->decoder_info_ptr[2], + /* table of sub-packet offsets */ + 0, + /* unknown, seems to be unused */ + this->pts / 90 + /* timestamp (the integer value from the stream) */ + }; + + lprintf ("chunk table\n"); + + +#ifdef LOG + printf ("libreal: got %d chunks\n", + buf->decoder_info[2] + 1); + + printf ("libreal: decoding %d bytes:\n", this->chunk_buffer_size); + xine_hexdump (this->chunk_buffer, this->chunk_buffer_size); + + printf ("libreal: transform_in:\n"); + xine_hexdump ((uint8_t *) transform_in, 6 * 4); + + printf ("libreal: chunk_table:\n"); + xine_hexdump ((uint8_t *) buf->decoder_info_ptr[2], + 2*(buf->decoder_info[2]+1)*sizeof(uint32_t)); +#endif + + result = this->rvyuv_transform (this->chunk_buffer, + this->frame_buffer, + &transform_in, + transform_out, + this->context); + + lprintf ("transform result: %08x\n", result); + lprintf ("transform_out:\n"); + #ifdef LOG + xine_hexdump ((uint8_t *) transform_out, 5 * 4); + #endif + + /* Sometimes the stream contains video of a different size + * to that specified in the realmedia header */ + if(transform_out[0] && ((transform_out[3] != this->width) || + (transform_out[4] != this->height))) { + this->width = transform_out[3]; + this->height = transform_out[4]; + + this->frame_size = this->width * this->height; + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->width); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->height); + } + + img = this->stream->video_out->get_frame (this->stream->video_out, + /* this->av_picture.linesize[0], */ + this->width, + this->height, + this->ratio, + XINE_IMGFMT_YV12, + VO_BOTH_FIELDS); + + img->pts = this->pts; + img->duration = this->duration; + _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->duration); + img->bad_frame = 0; + + yv12_to_yv12( + /* Y */ + this->frame_buffer, this->width, + img->base[0], img->pitches[0], + /* U */ + this->frame_buffer + this->frame_size, this->width/2, + img->base[1], img->pitches[1], + /* V */ + this->frame_buffer + this->frame_size * 5/4, this->width/2, + img->base[2], img->pitches[2], + /* width x height */ + this->width, this->height); + + img->draw(img, this->stream); + img->free(img); + + } else { + /* unsupported special buf */ + } + } + } + + lprintf ("decode_data...done\n"); +} + +static void realdec_flush (video_decoder_t *this_gen) { + /* realdec_decoder_t *this = (realdec_decoder_t *) this_gen; */ + + lprintf ("flush\n"); +} + +static void realdec_reset (video_decoder_t *this_gen) { + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + this->chunk_buffer_size = 0; +} + +static void realdec_discontinuity (video_decoder_t *this_gen) { + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + this->pts = 0; +} + +static void realdec_dispose (video_decoder_t *this_gen) { + + realdec_decoder_t *this = (realdec_decoder_t *) this_gen; + + lprintf ("dispose\n"); + + if (this->context) + this->stream->video_out->close(this->stream->video_out, this->stream); + + if (this->rvyuv_free && this->context) + this->rvyuv_free (this->context); + + if (this->rv_handle) + dlclose (this->rv_handle); + + if (this->frame_buffer) + free (this->frame_buffer); + + if (this->chunk_buffer) + free (this->chunk_buffer); + + free (this); + + lprintf ("dispose done\n"); +} + +static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, + xine_stream_t *stream) { + + real_class_t *cls = (real_class_t *) class_gen; + realdec_decoder_t *this ; + + this = (realdec_decoder_t *) xine_xmalloc (sizeof (realdec_decoder_t)); + + this->video_decoder.decode_data = realdec_decode_data; + this->video_decoder.flush = realdec_flush; + this->video_decoder.reset = realdec_reset; + this->video_decoder.discontinuity = realdec_discontinuity; + this->video_decoder.dispose = realdec_dispose; + this->stream = stream; + this->cls = cls; + + this->context = 0; + this->pts = 0; + + this->duration = 0; + + return &this->video_decoder; +} + +/* + * real plugin class + */ + +static char *get_identifier (video_decoder_class_t *this) { + return "realvdec"; +} + +static char *get_description (video_decoder_class_t *this) { + return "real binary-only codec based video decoder plugin"; +} + +static void dispose_class (video_decoder_class_t *this) { + free (this); +} + +void *init_realvdec (xine_t *xine, void *data) { + + real_class_t *this; + config_values_t *config = xine->config; + + this = (real_class_t *) xine_xmalloc (sizeof (real_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + _x_real_codecs_init(xine); + + return this; +} + +/* + * exported plugin catalog entry + */ + +static uint32_t supported_types[] = { BUF_VIDEO_RV20, + BUF_VIDEO_RV30, + BUF_VIDEO_RV40, + 0 }; + +const decoder_info_t dec_info_realvideo = { + supported_types, /* supported types */ + 7 /* priority */ +}; -- cgit v1.2.3 From 80ae291df82f5016ce0cfd927569e49e8ce25725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:35:03 +0200 Subject: Rename xine_decoder.c to xine_mpeg2_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libmpeg2/xine_decoder.c => src/libmpeg2/xine_mpeg2_decoder.c --- src/libmpeg2/Makefile.am | 12 +-- src/libmpeg2/xine_decoder.c | 184 -------------------------------------- src/libmpeg2/xine_mpeg2_decoder.c | 184 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 192 deletions(-) delete mode 100644 src/libmpeg2/xine_decoder.c create mode 100644 src/libmpeg2/xine_mpeg2_decoder.c (limited to 'src') diff --git a/src/libmpeg2/Makefile.am b/src/libmpeg2/Makefile.am index 550ce581f..66fb39f13 100644 --- a/src/libmpeg2/Makefile.am +++ b/src/libmpeg2/Makefile.am @@ -1,10 +1,6 @@ include $(top_srcdir)/misc/Makefile.common -AM_CFLAGS = $(LIBMPEG2_CFLAGS) - -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_mpeg2.la +xineplug_LTLIBRARIES = xineplug_decode_mpeg2.la xineplug_decode_mpeg2_la_SOURCES = \ cpu_state.c \ @@ -23,12 +19,12 @@ xineplug_decode_mpeg2_la_SOURCES = \ slice_xvmc.c \ slice_xvmc_vld.c \ stats.c \ - xine_decoder.c \ + xine_mpeg2_decoder.c \ libmpeg2_accel.c xineplug_decode_mpeg2_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB) -lm -xineplug_decode_mpeg2_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_mpeg2_la_LDFLAGS = -avoid-version -module +xineplug_decode_mpeg2_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBMPEG2_CFLAGS) +xineplug_decode_mpeg2_la_LDFLAGS = $(xineplug_ldflags) noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h \ libmpeg2_accel.h diff --git a/src/libmpeg2/xine_decoder.c b/src/libmpeg2/xine_decoder.c deleted file mode 100644 index 8c0d176c0..000000000 --- a/src/libmpeg2/xine_decoder.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.59 2006/07/10 22:08:29 dgp85 Exp $ - * - * stuff needed to turn libmpeg2 into a xine decoder plugin - */ - - -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "mpeg2_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "video_out.h" -#include "mpeg2.h" -#include "mpeg2_internal.h" -#include "buffer.h" - -typedef struct { - video_decoder_class_t decoder_class; -} mpeg2_class_t; - - -typedef struct mpeg2dec_decoder_s { - video_decoder_t video_decoder; - mpeg2dec_t mpeg2; - mpeg2_class_t *class; - xine_stream_t *stream; -} mpeg2dec_decoder_t; - -static void mpeg2dec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; - - lprintf ("decode_data, flags=0x%08x ...\n", buf->decoder_flags); - - /* handle aspect hints from xine-dvdnav */ - if (buf->decoder_flags & BUF_FLAG_SPECIAL) { - if (buf->decoder_info[1] == BUF_SPECIAL_ASPECT) { - this->mpeg2.force_aspect = buf->decoder_info[2]; - if (buf->decoder_info[3] == 0x1 && buf->decoder_info[2] == 3) - /* letterboxing is denied, we have to do pan&scan */ - this->mpeg2.force_pan_scan = 1; - else - this->mpeg2.force_pan_scan = 0; - } - return; - } - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - mpeg2_find_sequence_header (&this->mpeg2, buf->content, buf->content + buf->size); - } else { - - mpeg2_decode_data (&this->mpeg2, buf->content, buf->content + buf->size, - buf->pts); - } - - lprintf ("decode_data...done\n"); -} - -static void mpeg2dec_flush (video_decoder_t *this_gen) { - mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; - - lprintf ("flush\n"); - - mpeg2_flush (&this->mpeg2); -} - -static void mpeg2dec_reset (video_decoder_t *this_gen) { - mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; - - mpeg2_reset (&this->mpeg2); -} - -static void mpeg2dec_discontinuity (video_decoder_t *this_gen) { - mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; - - mpeg2_discontinuity (&this->mpeg2); -} - -static void mpeg2dec_dispose (video_decoder_t *this_gen) { - - mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; - - lprintf ("close\n"); - - mpeg2_close (&this->mpeg2); - - this->stream->video_out->close(this->stream->video_out, this->stream); - - free (this); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - mpeg2dec_decoder_t *this ; - - this = (mpeg2dec_decoder_t *) xine_xmalloc (sizeof (mpeg2dec_decoder_t)); - - this->video_decoder.decode_data = mpeg2dec_decode_data; - this->video_decoder.flush = mpeg2dec_flush; - this->video_decoder.reset = mpeg2dec_reset; - this->video_decoder.discontinuity = mpeg2dec_discontinuity; - this->video_decoder.dispose = mpeg2dec_dispose; - this->stream = stream; - this->class = (mpeg2_class_t *) class_gen; - this->mpeg2.stream = stream; - - mpeg2_init (&this->mpeg2, stream->video_out); - stream->video_out->open(stream->video_out, stream); - this->mpeg2.force_aspect = this->mpeg2.force_pan_scan = 0; - - return &this->video_decoder; -} - -/* - * mpeg2 plugin class - */ - -static char *get_identifier (video_decoder_class_t *this) { - return "mpeg2dec"; -} - -static char *get_description (video_decoder_class_t *this) { - return "mpeg2 based video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - mpeg2_class_t *this; - - this = (mpeg2_class_t *) xine_xmalloc (sizeof (mpeg2_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} -/* - * exported plugin catalog entry - */ - -static uint32_t supported_types[] = { BUF_VIDEO_MPEG, 0 }; - -static const decoder_info_t dec_info_mpeg2 = { - supported_types, /* supported types */ - 7 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "mpeg2", XINE_VERSION_CODE, &dec_info_mpeg2, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libmpeg2/xine_mpeg2_decoder.c b/src/libmpeg2/xine_mpeg2_decoder.c new file mode 100644 index 000000000..8c0d176c0 --- /dev/null +++ b/src/libmpeg2/xine_mpeg2_decoder.c @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.59 2006/07/10 22:08:29 dgp85 Exp $ + * + * stuff needed to turn libmpeg2 into a xine decoder plugin + */ + + +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "mpeg2_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "video_out.h" +#include "mpeg2.h" +#include "mpeg2_internal.h" +#include "buffer.h" + +typedef struct { + video_decoder_class_t decoder_class; +} mpeg2_class_t; + + +typedef struct mpeg2dec_decoder_s { + video_decoder_t video_decoder; + mpeg2dec_t mpeg2; + mpeg2_class_t *class; + xine_stream_t *stream; +} mpeg2dec_decoder_t; + +static void mpeg2dec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { + mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; + + lprintf ("decode_data, flags=0x%08x ...\n", buf->decoder_flags); + + /* handle aspect hints from xine-dvdnav */ + if (buf->decoder_flags & BUF_FLAG_SPECIAL) { + if (buf->decoder_info[1] == BUF_SPECIAL_ASPECT) { + this->mpeg2.force_aspect = buf->decoder_info[2]; + if (buf->decoder_info[3] == 0x1 && buf->decoder_info[2] == 3) + /* letterboxing is denied, we have to do pan&scan */ + this->mpeg2.force_pan_scan = 1; + else + this->mpeg2.force_pan_scan = 0; + } + return; + } + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) { + mpeg2_find_sequence_header (&this->mpeg2, buf->content, buf->content + buf->size); + } else { + + mpeg2_decode_data (&this->mpeg2, buf->content, buf->content + buf->size, + buf->pts); + } + + lprintf ("decode_data...done\n"); +} + +static void mpeg2dec_flush (video_decoder_t *this_gen) { + mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; + + lprintf ("flush\n"); + + mpeg2_flush (&this->mpeg2); +} + +static void mpeg2dec_reset (video_decoder_t *this_gen) { + mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; + + mpeg2_reset (&this->mpeg2); +} + +static void mpeg2dec_discontinuity (video_decoder_t *this_gen) { + mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; + + mpeg2_discontinuity (&this->mpeg2); +} + +static void mpeg2dec_dispose (video_decoder_t *this_gen) { + + mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen; + + lprintf ("close\n"); + + mpeg2_close (&this->mpeg2); + + this->stream->video_out->close(this->stream->video_out, this->stream); + + free (this); +} + +static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { + mpeg2dec_decoder_t *this ; + + this = (mpeg2dec_decoder_t *) xine_xmalloc (sizeof (mpeg2dec_decoder_t)); + + this->video_decoder.decode_data = mpeg2dec_decode_data; + this->video_decoder.flush = mpeg2dec_flush; + this->video_decoder.reset = mpeg2dec_reset; + this->video_decoder.discontinuity = mpeg2dec_discontinuity; + this->video_decoder.dispose = mpeg2dec_dispose; + this->stream = stream; + this->class = (mpeg2_class_t *) class_gen; + this->mpeg2.stream = stream; + + mpeg2_init (&this->mpeg2, stream->video_out); + stream->video_out->open(stream->video_out, stream); + this->mpeg2.force_aspect = this->mpeg2.force_pan_scan = 0; + + return &this->video_decoder; +} + +/* + * mpeg2 plugin class + */ + +static char *get_identifier (video_decoder_class_t *this) { + return "mpeg2dec"; +} + +static char *get_description (video_decoder_class_t *this) { + return "mpeg2 based video decoder plugin"; +} + +static void dispose_class (video_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + mpeg2_class_t *this; + + this = (mpeg2_class_t *) xine_xmalloc (sizeof (mpeg2_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} +/* + * exported plugin catalog entry + */ + +static uint32_t supported_types[] = { BUF_VIDEO_MPEG, 0 }; + +static const decoder_info_t dec_info_mpeg2 = { + supported_types, /* supported types */ + 7 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_VIDEO_DECODER, 18, "mpeg2", XINE_VERSION_CODE, &dec_info_mpeg2, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From c95d450dadb640aa3ee4cb9536626fe183549ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:36:40 +0200 Subject: Rename xine_decoder.c to xine_mpeg2new_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libmpeg2new/xine_decoder.c => src/libmpeg2new/xine_mpeg2new_decoder.c --- src/libmpeg2new/Makefile.am | 11 +- src/libmpeg2new/xine_decoder.c | 519 -------------------------------- src/libmpeg2new/xine_mpeg2new_decoder.c | 519 ++++++++++++++++++++++++++++++++ 3 files changed, 523 insertions(+), 526 deletions(-) delete mode 100644 src/libmpeg2new/xine_decoder.c create mode 100644 src/libmpeg2new/xine_mpeg2new_decoder.c (limited to 'src') diff --git a/src/libmpeg2new/Makefile.am b/src/libmpeg2new/Makefile.am index 03dae6cba..49959da86 100644 --- a/src/libmpeg2new/Makefile.am +++ b/src/libmpeg2new/Makefile.am @@ -1,16 +1,13 @@ include $(top_srcdir)/misc/Makefile.common -AM_CFLAGS = $(LIBMPEG2_CFLAGS) - SUBDIRS = libmpeg2 -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_mpeg2.la +xineplug_LTLIBRARIES = xineplug_decode_mpeg2.la xineplug_decode_mpeg2_la_SOURCES = \ - xine_decoder.c + xine_mpeg2_decoder.c +xineplug_decode_mpeg2_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBMPEG2_CFLAGS) xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB) ./libmpeg2/libmpeg2.la -xineplug_decode_mpeg2_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ +xineplug_decode_mpeg2_la_LDFLAGS = $(xineplug_ldflags) diff --git a/src/libmpeg2new/xine_decoder.c b/src/libmpeg2new/xine_decoder.c deleted file mode 100644 index 9e36772b7..000000000 --- a/src/libmpeg2new/xine_decoder.c +++ /dev/null @@ -1,519 +0,0 @@ -/* - * Copyright (C) 2000-2004 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.22 2004/12/16 13:59:06 mroi Exp $ - * - * stuff needed to turn libmpeg2 into a xine decoder plugin - */ - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "./include/mpeg2.h" -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" - - - -#define LOG -#define LOG_FRAME_ALLOC_FREE -#define LOG_ENTRY -#define LOG_FRAME_COUNTER - - -typedef struct { - video_decoder_class_t decoder_class; -} mpeg2_class_t; - -typedef struct { - uint32_t id; - vo_frame_t * img; -} img_state_t; - -typedef struct mpeg2_video_decoder_s { - video_decoder_t video_decoder; - mpeg2dec_t *mpeg2dec; - mpeg2_class_t *class; - xine_stream_t *stream; - int32_t force_aspect; - int force_pan_scan; - double ratio; - img_state_t img_state[30]; - uint32_t frame_number; - uint32_t rff_pattern; - -} mpeg2_video_decoder_t; - - -static void mpeg2_video_print_bad_state(img_state_t * img_state) { - int32_t n,m; - m=0; - for(n=0;n<30;n++) { - if (img_state[n].id>0) { - printf("%d = %u\n",n, img_state[n].id); - m++; - } - } - if (m > 3) _x_abort(); - if (m == 0) printf("NO FRAMES\n"); -} - -static void mpeg2_video_free_all(img_state_t * img_state) { - int32_t n,m; - vo_frame_t * img; - printf("libmpeg2new:free_all\n"); - for(n=0;n<30;n++) { - if (img_state[n].id>0) { - img = img_state[n].img; - img->free(img); - img_state[n].id = 0; - } - } -} - - -static void mpeg2_video_print_fbuf(const mpeg2_fbuf_t * fbuf) { - printf("%p",fbuf); - vo_frame_t * img; - if (fbuf) { - img = (vo_frame_t *) fbuf->id; - if (img) { - printf (", img=%p, (id=%d)\n", - img, img->id); - } else { - printf (", img=NULL\n"); - } - } else { - printf ("\n"); - } -} - -static void mpeg2_video_decode_data (video_decoder_t *this_gen, buf_element_t *buf_element) { - mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; - uint8_t * current = buf_element->content; - uint8_t * end = buf_element->content + buf_element->size; - const mpeg2_info_t * info; - mpeg2_state_t state; - vo_frame_t * img; - uint32_t picture_structure; - int32_t frame_skipping; - - /* handle aspect hints from xine-dvdnav */ - if (buf_element->decoder_flags & BUF_FLAG_SPECIAL) { - if (buf_element->decoder_info[1] == BUF_SPECIAL_ASPECT) { - this->force_aspect = buf_element->decoder_info[2]; - if (buf_element->decoder_info[3] == 0x1 && buf_element->decoder_info[2] == 3) - /* letterboxing is denied, we have to do pan&scan */ - this->force_pan_scan = 1; - else - this->force_pan_scan = 0; - } - - return; - } - - if (buf_element->decoder_flags != 0) return; - -#ifdef LOG_ENTRY - printf ("libmpeg2: decode_data: enter\n"); -#endif - - mpeg2_buffer (this->mpeg2dec, current, end); - - info = mpeg2_info (this->mpeg2dec); - - while ((state = mpeg2_parse (this->mpeg2dec)) != STATE_BUFFER) { - switch (state) { - case STATE_SEQUENCE: - /* might set nb fbuf, convert format, stride */ - /* might set fbufs */ - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_BITRATE, info->sequence->byte_rate * 8); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, info->sequence->picture_width); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, info->sequence->picture_height); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, info->sequence->frame_period / 300); - if (this->force_aspect) info->sequence->pixel_width = this->force_aspect; - switch (info->sequence->pixel_width) { - case 3: - this->ratio = 16.0 / 9.0; - break; - case 4: - this->ratio = 2.11; - break; - case 2: - this->ratio = 4.0 / 3.0; - break; - case 1: - default: - this->ratio = (double)info->sequence->picture_width/(double)info->sequence->picture_height; - break; - } - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, (int)(10000*this->ratio)); - - if (info->sequence->flags & SEQ_FLAG_MPEG2) { - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "MPEG 2 (libmpeg2new)"); - } else { - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "MPEG 1 (libmpeg2new)"); - } - - break; - case STATE_PICTURE: - /* might skip */ - /* might set fbuf */ - if (info->current_picture->nb_fields == 1) { - picture_structure = info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? VO_TOP_FIELD : VO_BOTTOM_FIELD; - } else { - picture_structure = VO_BOTH_FIELDS; - } - - img = this->stream->video_out->get_frame (this->stream->video_out, - info->sequence->picture_width, - info->sequence->picture_height, - this->ratio, - XINE_IMGFMT_YV12, - picture_structure); - this->frame_number++; -#ifdef LOG_FRAME_COUNTER - printf("libmpeg2:frame_number=%d\n",this->frame_number); -#endif - img->top_field_first = info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? 1 : 0; - img->repeat_first_field = (info->current_picture->nb_fields > 2) ? 1 : 0; - img->duration=info->sequence->frame_period / 300; - if( ((this->rff_pattern & 0xff) == 0xaa || - (this->rff_pattern & 0xff) == 0x55) ) { - /* special case for ntsc 3:2 pulldown */ - img->duration += img->duration/4; - } else { - if( img->repeat_first_field ) { - img->duration = (img->duration * info->current_picture->nb_fields) / 2; - } - } - - if ((info->current_picture->flags & 7) == 1) { - img->pts=buf_element->pts; /* If an I frame, use PTS */ - } else { - img->pts=0; - } - - -#ifdef LOG_FRAME_ALLOC_FREE - printf ("libmpeg2:decode_data:get_frame xine=%p (id=%d)\n", img,img->id); -#endif - if (this->img_state[img->id].id != 0) { - printf ("libmpeg2:decode_data:get_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id].id); - _x_abort(); - } - - this->img_state[img->id].id = 1; - this->img_state[img->id].img = img; - - mpeg2_set_buf (this->mpeg2dec, img->base, img); - break; - case STATE_SLICE: - case STATE_END: -#if 0 - printf("libmpeg2:decode_data:current_fbuf="); - mpeg2_video_print_fbuf(info->current_fbuf); - printf("libmpeg2:decode_data:display_fbuf="); - mpeg2_video_print_fbuf(info->display_fbuf); - printf("libmpeg2:decode_data:discard_fbuf="); - mpeg2_video_print_fbuf(info->discard_fbuf); -#endif - /* draw current picture */ - /* might free frame buffer */ - if (info->display_fbuf && info->display_fbuf->id) { - img = (vo_frame_t *) info->display_fbuf->id; - /* this should be used to detect any special rff pattern */ - this->rff_pattern = this->rff_pattern << 1; - this->rff_pattern |= img->repeat_first_field; - -#ifdef LOG_FRAME_ALLOC_FREE - printf ("libmpeg2:decode_data:draw_frame xine=%p, fbuf=%p, id=%d \n", img, info->display_fbuf, img->id); -#endif - if (this->img_state[img->id].id != 1) { - printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id].id); - _x_abort(); - } - if (this->img_state[img->id].id == 1) { - frame_skipping = img->draw (img, this->stream); - /* FIXME: Handle skipping */ - this->img_state[img->id].id = 2; - } - - } - if (info->discard_fbuf && !info->discard_fbuf->id) { - printf ("libmpeg2:decode_data:BAD free_frame discard: xine=%p, fbuf=%p\n", info->discard_fbuf->id, info->discard_fbuf); - //_x_abort(); - } - if (info->discard_fbuf && info->discard_fbuf->id) { - img = (vo_frame_t *) info->discard_fbuf->id; -#ifdef LOG_FRAME_ALLOC_FREE - printf ("libmpeg2:decode_data:free_frame xine=%p, fbuf=%p,id=%d\n", img, info->discard_fbuf, img->id); -#endif - if (this->img_state[img->id].id != 2) { - printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id].id); - _x_abort(); - } - if (this->img_state[img->id].id == 2) { - img->free(img); - this->img_state[img->id].id = 0; - } - } -#ifdef LOG_FRAME_ALLOC_FREE - mpeg2_video_print_bad_state(this->img_state); -#endif - break; - case STATE_GOP: - break; - default: - printf("libmpeg2new: STATE unknown %d\n",state); - break; - } - - } -#ifdef LOG_ENTRY - printf ("libmpeg2: decode_data: exit\n"); -#endif - -} - -static void mpeg2_video_flush (video_decoder_t *this_gen) { - mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; - -#ifdef LOG_ENTRY - printf ("libmpeg2: flush\n"); -#endif - -/* mpeg2_flush (&this->mpeg2); */ -} - -static void mpeg2_video_reset (video_decoder_t *this_gen) { - mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; - int32_t state; - const mpeg2_info_t * info; - vo_frame_t * img; - int32_t frame_skipping; - -#ifdef LOG_ENTRY - printf ("libmpeg2: reset\n"); -#endif - mpeg2_reset (this->mpeg2dec, 1); /* 1 for full reset */ - mpeg2_video_free_all(this->img_state); - - -#if 0 /* This bit of code does not work yet. */ - info = mpeg2_info (this->mpeg2dec); - state = mpeg2_reset (this->mpeg2dec); - printf("reset state1:%d\n",state); - if (info->display_fbuf && info->display_fbuf->id) { - img = (vo_frame_t *) info->display_fbuf->id; - - if (this->img_state[img->id] != 1) { - printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); - _x_abort(); - } - if (this->img_state[img->id] == 1) { - frame_skipping = img->draw (img, this->stream); - /* FIXME: Handle skipping */ - this->img_state[img->id] = 2; - } - } - - if (info->discard_fbuf && !info->discard_fbuf->id) { - printf ("libmpeg2:decode_data:BAD free_frame discard_fbuf=%p\n", info->discard_fbuf); - _x_abort(); - } - if (info->discard_fbuf && info->discard_fbuf->id) { - img = (vo_frame_t *) info->discard_fbuf->id; - if (this->img_state[img->id] != 2) { - printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); - _x_abort(); - } - if (this->img_state[img->id] == 2) { - img->free(img); - this->img_state[img->id] = 0; - } - } - state = mpeg2_parse (this->mpeg2dec); - printf("reset state2:%d\n",state); - if (info->display_fbuf && info->display_fbuf->id) { - img = (vo_frame_t *) info->display_fbuf->id; - - if (this->img_state[img->id] != 1) { - printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); - _x_abort(); - } - if (this->img_state[img->id] == 1) { - frame_skipping = img->draw (img, this->stream); - /* FIXME: Handle skipping */ - this->img_state[img->id] = 2; - } - } - - if (info->discard_fbuf && !info->discard_fbuf->id) { - printf ("libmpeg2:decode_data:BAD free_frame discard_fbuf=%p\n", info->discard_fbuf); - _x_abort(); - } - if (info->discard_fbuf && info->discard_fbuf->id) { - img = (vo_frame_t *) info->discard_fbuf->id; - if (this->img_state[img->id] != 2) { - printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); - _x_abort(); - } - if (this->img_state[img->id] == 2) { - img->free(img); - this->img_state[img->id] = 0; - } - } - state = mpeg2_parse (this->mpeg2dec); - printf("reset state3:%d\n",state); - if (info->display_fbuf && info->display_fbuf->id) { - img = (vo_frame_t *) info->display_fbuf->id; - - if (this->img_state[img->id] != 1) { - printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); - _x_abort(); - } - if (this->img_state[img->id] == 1) { - frame_skipping = img->draw (img, this->stream); - /* FIXME: Handle skipping */ - this->img_state[img->id] = 2; - } - } - - if (info->discard_fbuf && !info->discard_fbuf->id) { - printf ("libmpeg2:decode_data:BAD free_frame discard_fbuf=%p\n", info->discard_fbuf); - _x_abort(); - } - if (info->discard_fbuf && info->discard_fbuf->id) { - img = (vo_frame_t *) info->discard_fbuf->id; - if (this->img_state[img->id] != 2) { - printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); - _x_abort(); - } - if (this->img_state[img->id] == 2) { - img->free(img); - this->img_state[img->id] = 0; - } - } -#endif - -} - -static void mpeg2_video_discontinuity (video_decoder_t *this_gen) { - mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; - -#ifdef LOG_ENTRY - printf ("libmpeg2: dicontinuity\n"); -#endif -/* mpeg2_discontinuity (&this->mpeg2dec); */ -} - -static void mpeg2_video_dispose (video_decoder_t *this_gen) { - - mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; - -#ifdef LOG_ENTRY - printf ("libmpeg2: close\n"); -#endif - - mpeg2_close (this->mpeg2dec); - - this->stream->video_out->close(this->stream->video_out, this->stream); - - free (this); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - mpeg2_video_decoder_t *this ; - int32_t n; - - this = (mpeg2_video_decoder_t *) xine_xmalloc (sizeof (mpeg2_video_decoder_t)); - - this->video_decoder.decode_data = mpeg2_video_decode_data; - this->video_decoder.flush = mpeg2_video_flush; - this->video_decoder.reset = mpeg2_video_reset; - this->video_decoder.discontinuity = mpeg2_video_discontinuity; - this->video_decoder.dispose = mpeg2_video_dispose; - this->stream = stream; - this->class = (mpeg2_class_t *) class_gen; - this->frame_number=0; - this->rff_pattern=0; - - this->mpeg2dec = mpeg2_init (); - mpeg2_custom_fbuf (this->mpeg2dec, 1); /* <- Force libmpeg2 to use xine frame buffers. */ - stream->video_out->open(stream->video_out, stream); - this->force_aspect = this->force_pan_scan = 0; - for(n=0;n<30;n++) this->img_state[n].id=0; - - return &this->video_decoder; -} - -/* - * mpeg2 plugin class - */ - -static char *get_identifier (video_decoder_class_t *this) { - return "mpeg2new"; -} - -static char *get_description (video_decoder_class_t *this) { - return "mpeg2 based video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - mpeg2_class_t *this; - - this = (mpeg2_class_t *) xine_xmalloc (sizeof (mpeg2_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} -/* - * exported plugin catalog entry - */ - -static uint32_t supported_types[] = { BUF_VIDEO_MPEG, 0 }; - -static decoder_info_t dec_info_mpeg2 = { - supported_types, /* supported types */ - 6 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "mpeg2new", XINE_VERSION_CODE, &dec_info_mpeg2, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libmpeg2new/xine_mpeg2new_decoder.c b/src/libmpeg2new/xine_mpeg2new_decoder.c new file mode 100644 index 000000000..9e36772b7 --- /dev/null +++ b/src/libmpeg2new/xine_mpeg2new_decoder.c @@ -0,0 +1,519 @@ +/* + * Copyright (C) 2000-2004 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.22 2004/12/16 13:59:06 mroi Exp $ + * + * stuff needed to turn libmpeg2 into a xine decoder plugin + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "./include/mpeg2.h" +#include "xine_internal.h" +#include "video_out.h" +#include "buffer.h" + + + +#define LOG +#define LOG_FRAME_ALLOC_FREE +#define LOG_ENTRY +#define LOG_FRAME_COUNTER + + +typedef struct { + video_decoder_class_t decoder_class; +} mpeg2_class_t; + +typedef struct { + uint32_t id; + vo_frame_t * img; +} img_state_t; + +typedef struct mpeg2_video_decoder_s { + video_decoder_t video_decoder; + mpeg2dec_t *mpeg2dec; + mpeg2_class_t *class; + xine_stream_t *stream; + int32_t force_aspect; + int force_pan_scan; + double ratio; + img_state_t img_state[30]; + uint32_t frame_number; + uint32_t rff_pattern; + +} mpeg2_video_decoder_t; + + +static void mpeg2_video_print_bad_state(img_state_t * img_state) { + int32_t n,m; + m=0; + for(n=0;n<30;n++) { + if (img_state[n].id>0) { + printf("%d = %u\n",n, img_state[n].id); + m++; + } + } + if (m > 3) _x_abort(); + if (m == 0) printf("NO FRAMES\n"); +} + +static void mpeg2_video_free_all(img_state_t * img_state) { + int32_t n,m; + vo_frame_t * img; + printf("libmpeg2new:free_all\n"); + for(n=0;n<30;n++) { + if (img_state[n].id>0) { + img = img_state[n].img; + img->free(img); + img_state[n].id = 0; + } + } +} + + +static void mpeg2_video_print_fbuf(const mpeg2_fbuf_t * fbuf) { + printf("%p",fbuf); + vo_frame_t * img; + if (fbuf) { + img = (vo_frame_t *) fbuf->id; + if (img) { + printf (", img=%p, (id=%d)\n", + img, img->id); + } else { + printf (", img=NULL\n"); + } + } else { + printf ("\n"); + } +} + +static void mpeg2_video_decode_data (video_decoder_t *this_gen, buf_element_t *buf_element) { + mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; + uint8_t * current = buf_element->content; + uint8_t * end = buf_element->content + buf_element->size; + const mpeg2_info_t * info; + mpeg2_state_t state; + vo_frame_t * img; + uint32_t picture_structure; + int32_t frame_skipping; + + /* handle aspect hints from xine-dvdnav */ + if (buf_element->decoder_flags & BUF_FLAG_SPECIAL) { + if (buf_element->decoder_info[1] == BUF_SPECIAL_ASPECT) { + this->force_aspect = buf_element->decoder_info[2]; + if (buf_element->decoder_info[3] == 0x1 && buf_element->decoder_info[2] == 3) + /* letterboxing is denied, we have to do pan&scan */ + this->force_pan_scan = 1; + else + this->force_pan_scan = 0; + } + + return; + } + + if (buf_element->decoder_flags != 0) return; + +#ifdef LOG_ENTRY + printf ("libmpeg2: decode_data: enter\n"); +#endif + + mpeg2_buffer (this->mpeg2dec, current, end); + + info = mpeg2_info (this->mpeg2dec); + + while ((state = mpeg2_parse (this->mpeg2dec)) != STATE_BUFFER) { + switch (state) { + case STATE_SEQUENCE: + /* might set nb fbuf, convert format, stride */ + /* might set fbufs */ + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_BITRATE, info->sequence->byte_rate * 8); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, info->sequence->picture_width); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, info->sequence->picture_height); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, info->sequence->frame_period / 300); + if (this->force_aspect) info->sequence->pixel_width = this->force_aspect; + switch (info->sequence->pixel_width) { + case 3: + this->ratio = 16.0 / 9.0; + break; + case 4: + this->ratio = 2.11; + break; + case 2: + this->ratio = 4.0 / 3.0; + break; + case 1: + default: + this->ratio = (double)info->sequence->picture_width/(double)info->sequence->picture_height; + break; + } + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, (int)(10000*this->ratio)); + + if (info->sequence->flags & SEQ_FLAG_MPEG2) { + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "MPEG 2 (libmpeg2new)"); + } else { + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "MPEG 1 (libmpeg2new)"); + } + + break; + case STATE_PICTURE: + /* might skip */ + /* might set fbuf */ + if (info->current_picture->nb_fields == 1) { + picture_structure = info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? VO_TOP_FIELD : VO_BOTTOM_FIELD; + } else { + picture_structure = VO_BOTH_FIELDS; + } + + img = this->stream->video_out->get_frame (this->stream->video_out, + info->sequence->picture_width, + info->sequence->picture_height, + this->ratio, + XINE_IMGFMT_YV12, + picture_structure); + this->frame_number++; +#ifdef LOG_FRAME_COUNTER + printf("libmpeg2:frame_number=%d\n",this->frame_number); +#endif + img->top_field_first = info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? 1 : 0; + img->repeat_first_field = (info->current_picture->nb_fields > 2) ? 1 : 0; + img->duration=info->sequence->frame_period / 300; + if( ((this->rff_pattern & 0xff) == 0xaa || + (this->rff_pattern & 0xff) == 0x55) ) { + /* special case for ntsc 3:2 pulldown */ + img->duration += img->duration/4; + } else { + if( img->repeat_first_field ) { + img->duration = (img->duration * info->current_picture->nb_fields) / 2; + } + } + + if ((info->current_picture->flags & 7) == 1) { + img->pts=buf_element->pts; /* If an I frame, use PTS */ + } else { + img->pts=0; + } + + +#ifdef LOG_FRAME_ALLOC_FREE + printf ("libmpeg2:decode_data:get_frame xine=%p (id=%d)\n", img,img->id); +#endif + if (this->img_state[img->id].id != 0) { + printf ("libmpeg2:decode_data:get_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id].id); + _x_abort(); + } + + this->img_state[img->id].id = 1; + this->img_state[img->id].img = img; + + mpeg2_set_buf (this->mpeg2dec, img->base, img); + break; + case STATE_SLICE: + case STATE_END: +#if 0 + printf("libmpeg2:decode_data:current_fbuf="); + mpeg2_video_print_fbuf(info->current_fbuf); + printf("libmpeg2:decode_data:display_fbuf="); + mpeg2_video_print_fbuf(info->display_fbuf); + printf("libmpeg2:decode_data:discard_fbuf="); + mpeg2_video_print_fbuf(info->discard_fbuf); +#endif + /* draw current picture */ + /* might free frame buffer */ + if (info->display_fbuf && info->display_fbuf->id) { + img = (vo_frame_t *) info->display_fbuf->id; + /* this should be used to detect any special rff pattern */ + this->rff_pattern = this->rff_pattern << 1; + this->rff_pattern |= img->repeat_first_field; + +#ifdef LOG_FRAME_ALLOC_FREE + printf ("libmpeg2:decode_data:draw_frame xine=%p, fbuf=%p, id=%d \n", img, info->display_fbuf, img->id); +#endif + if (this->img_state[img->id].id != 1) { + printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id].id); + _x_abort(); + } + if (this->img_state[img->id].id == 1) { + frame_skipping = img->draw (img, this->stream); + /* FIXME: Handle skipping */ + this->img_state[img->id].id = 2; + } + + } + if (info->discard_fbuf && !info->discard_fbuf->id) { + printf ("libmpeg2:decode_data:BAD free_frame discard: xine=%p, fbuf=%p\n", info->discard_fbuf->id, info->discard_fbuf); + //_x_abort(); + } + if (info->discard_fbuf && info->discard_fbuf->id) { + img = (vo_frame_t *) info->discard_fbuf->id; +#ifdef LOG_FRAME_ALLOC_FREE + printf ("libmpeg2:decode_data:free_frame xine=%p, fbuf=%p,id=%d\n", img, info->discard_fbuf, img->id); +#endif + if (this->img_state[img->id].id != 2) { + printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id].id); + _x_abort(); + } + if (this->img_state[img->id].id == 2) { + img->free(img); + this->img_state[img->id].id = 0; + } + } +#ifdef LOG_FRAME_ALLOC_FREE + mpeg2_video_print_bad_state(this->img_state); +#endif + break; + case STATE_GOP: + break; + default: + printf("libmpeg2new: STATE unknown %d\n",state); + break; + } + + } +#ifdef LOG_ENTRY + printf ("libmpeg2: decode_data: exit\n"); +#endif + +} + +static void mpeg2_video_flush (video_decoder_t *this_gen) { + mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; + +#ifdef LOG_ENTRY + printf ("libmpeg2: flush\n"); +#endif + +/* mpeg2_flush (&this->mpeg2); */ +} + +static void mpeg2_video_reset (video_decoder_t *this_gen) { + mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; + int32_t state; + const mpeg2_info_t * info; + vo_frame_t * img; + int32_t frame_skipping; + +#ifdef LOG_ENTRY + printf ("libmpeg2: reset\n"); +#endif + mpeg2_reset (this->mpeg2dec, 1); /* 1 for full reset */ + mpeg2_video_free_all(this->img_state); + + +#if 0 /* This bit of code does not work yet. */ + info = mpeg2_info (this->mpeg2dec); + state = mpeg2_reset (this->mpeg2dec); + printf("reset state1:%d\n",state); + if (info->display_fbuf && info->display_fbuf->id) { + img = (vo_frame_t *) info->display_fbuf->id; + + if (this->img_state[img->id] != 1) { + printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); + _x_abort(); + } + if (this->img_state[img->id] == 1) { + frame_skipping = img->draw (img, this->stream); + /* FIXME: Handle skipping */ + this->img_state[img->id] = 2; + } + } + + if (info->discard_fbuf && !info->discard_fbuf->id) { + printf ("libmpeg2:decode_data:BAD free_frame discard_fbuf=%p\n", info->discard_fbuf); + _x_abort(); + } + if (info->discard_fbuf && info->discard_fbuf->id) { + img = (vo_frame_t *) info->discard_fbuf->id; + if (this->img_state[img->id] != 2) { + printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); + _x_abort(); + } + if (this->img_state[img->id] == 2) { + img->free(img); + this->img_state[img->id] = 0; + } + } + state = mpeg2_parse (this->mpeg2dec); + printf("reset state2:%d\n",state); + if (info->display_fbuf && info->display_fbuf->id) { + img = (vo_frame_t *) info->display_fbuf->id; + + if (this->img_state[img->id] != 1) { + printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); + _x_abort(); + } + if (this->img_state[img->id] == 1) { + frame_skipping = img->draw (img, this->stream); + /* FIXME: Handle skipping */ + this->img_state[img->id] = 2; + } + } + + if (info->discard_fbuf && !info->discard_fbuf->id) { + printf ("libmpeg2:decode_data:BAD free_frame discard_fbuf=%p\n", info->discard_fbuf); + _x_abort(); + } + if (info->discard_fbuf && info->discard_fbuf->id) { + img = (vo_frame_t *) info->discard_fbuf->id; + if (this->img_state[img->id] != 2) { + printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); + _x_abort(); + } + if (this->img_state[img->id] == 2) { + img->free(img); + this->img_state[img->id] = 0; + } + } + state = mpeg2_parse (this->mpeg2dec); + printf("reset state3:%d\n",state); + if (info->display_fbuf && info->display_fbuf->id) { + img = (vo_frame_t *) info->display_fbuf->id; + + if (this->img_state[img->id] != 1) { + printf ("libmpeg2:decode_data:draw_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); + _x_abort(); + } + if (this->img_state[img->id] == 1) { + frame_skipping = img->draw (img, this->stream); + /* FIXME: Handle skipping */ + this->img_state[img->id] = 2; + } + } + + if (info->discard_fbuf && !info->discard_fbuf->id) { + printf ("libmpeg2:decode_data:BAD free_frame discard_fbuf=%p\n", info->discard_fbuf); + _x_abort(); + } + if (info->discard_fbuf && info->discard_fbuf->id) { + img = (vo_frame_t *) info->discard_fbuf->id; + if (this->img_state[img->id] != 2) { + printf ("libmpeg2:decode_data:free_frame id=%d BAD STATE:%d\n", img->id, this->img_state[img->id]); + _x_abort(); + } + if (this->img_state[img->id] == 2) { + img->free(img); + this->img_state[img->id] = 0; + } + } +#endif + +} + +static void mpeg2_video_discontinuity (video_decoder_t *this_gen) { + mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; + +#ifdef LOG_ENTRY + printf ("libmpeg2: dicontinuity\n"); +#endif +/* mpeg2_discontinuity (&this->mpeg2dec); */ +} + +static void mpeg2_video_dispose (video_decoder_t *this_gen) { + + mpeg2_video_decoder_t *this = (mpeg2_video_decoder_t *) this_gen; + +#ifdef LOG_ENTRY + printf ("libmpeg2: close\n"); +#endif + + mpeg2_close (this->mpeg2dec); + + this->stream->video_out->close(this->stream->video_out, this->stream); + + free (this); +} + +static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { + mpeg2_video_decoder_t *this ; + int32_t n; + + this = (mpeg2_video_decoder_t *) xine_xmalloc (sizeof (mpeg2_video_decoder_t)); + + this->video_decoder.decode_data = mpeg2_video_decode_data; + this->video_decoder.flush = mpeg2_video_flush; + this->video_decoder.reset = mpeg2_video_reset; + this->video_decoder.discontinuity = mpeg2_video_discontinuity; + this->video_decoder.dispose = mpeg2_video_dispose; + this->stream = stream; + this->class = (mpeg2_class_t *) class_gen; + this->frame_number=0; + this->rff_pattern=0; + + this->mpeg2dec = mpeg2_init (); + mpeg2_custom_fbuf (this->mpeg2dec, 1); /* <- Force libmpeg2 to use xine frame buffers. */ + stream->video_out->open(stream->video_out, stream); + this->force_aspect = this->force_pan_scan = 0; + for(n=0;n<30;n++) this->img_state[n].id=0; + + return &this->video_decoder; +} + +/* + * mpeg2 plugin class + */ + +static char *get_identifier (video_decoder_class_t *this) { + return "mpeg2new"; +} + +static char *get_description (video_decoder_class_t *this) { + return "mpeg2 based video decoder plugin"; +} + +static void dispose_class (video_decoder_class_t *this) { + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + mpeg2_class_t *this; + + this = (mpeg2_class_t *) xine_xmalloc (sizeof (mpeg2_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} +/* + * exported plugin catalog entry + */ + +static uint32_t supported_types[] = { BUF_VIDEO_MPEG, 0 }; + +static decoder_info_t dec_info_mpeg2 = { + supported_types, /* supported types */ + 6 /* priority */ +}; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_VIDEO_DECODER, 18, "mpeg2new", XINE_VERSION_CODE, &dec_info_mpeg2, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From b87beb11fd9a5b253f301069348198950e529038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:40:45 +0200 Subject: Rename xine_decoder.c to xine_musepack_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libmusepack/xine_decoder.c => src/libmusepack/xine_musepack_decoder.c --- src/libmusepack/Makefile.am | 9 +- src/libmusepack/xine_decoder.c | 471 -------------------------------- src/libmusepack/xine_musepack_decoder.c | 471 ++++++++++++++++++++++++++++++++ 3 files changed, 474 insertions(+), 477 deletions(-) delete mode 100644 src/libmusepack/xine_decoder.c create mode 100644 src/libmusepack/xine_musepack_decoder.c (limited to 'src') diff --git a/src/libmusepack/Makefile.am b/src/libmusepack/Makefile.am index 021ec0985..d39426597 100644 --- a/src/libmusepack/Makefile.am +++ b/src/libmusepack/Makefile.am @@ -4,10 +4,8 @@ SUBDIRS = musepack EXTRA_DIST = diff_against_svn.patch -libdir = $(XINE_PLUGINDIR) - if MUSEPACK -lib_LTLIBRARIES = xineplug_decode_mpc.la +xineplug_LTLIBRARIES = xineplug_decode_mpc.la endif if EXTERNAL_MPCDEC @@ -23,7 +21,6 @@ else xineplug_decode_mpc_la_LIBADD = $(XINE_LIB) endif -xineplug_decode_mpc_la_SOURCES = $(internal_sources) xine_decoder.c +xineplug_decode_mpc_la_SOURCES = $(internal_sources) xine_musepack_decoder.c xineplug_decode_mpc_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_mpc_la_LDFLAGS = -avoid-version -module - +xineplug_decode_mpc_la_LDFLAGS = $(xineplug_ldflags) diff --git a/src/libmusepack/xine_decoder.c b/src/libmusepack/xine_decoder.c deleted file mode 100644 index 26c2eddf5..000000000 --- a/src/libmusepack/xine_decoder.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright (C) 2005 the xine project - * - * This file is part of xine, a free 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 - * - * xine interface to libmusepack by James Stembridge - * - * TODO: - * 32bit float output - * Seeking?? - * - * $Id: xine_decoder.c,v 1.10 2007/01/19 02:35:36 dgp85 Exp $ - */ - -#include -#include -#include -#include -#include - -#define LOG_MODULE "mpc_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" -#include "xineutils.h" - -#ifdef HAVE_MPCDEC_MPCDEC_H -# include -#else -# include "musepack/musepack.h" -#endif - -#define MPC_DECODER_MEMSIZE 65536 -#define MPC_DECODER_MEMSIZE2 (MPC_DECODER_MEMSIZE/2) - -#define INIT_BUFSIZE (MPC_DECODER_MEMSIZE*2) - -typedef struct { - audio_decoder_class_t decoder_class; -} mpc_class_t; - -typedef struct mpc_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int sample_rate; /* audio sample rate */ - int bits_per_sample; /* bits/sample, usually 8 or 16 */ - int channels; /* 1 or 2, usually */ - - int output_open; /* flag to indicate audio is ready */ - - unsigned char *buf; /* data accumulation buffer */ - unsigned int buf_max; /* maximum size of buf */ - unsigned int read; /* size of accum. data already read */ - unsigned int size; /* size of accumulated data in buf */ - - mpc_reader reader; - mpc_streaminfo streaminfo; - mpc_decoder decoder; - - int decoder_ok; - unsigned int current_frame; - - int32_t file_size; - -} mpc_decoder_t; - - -/************************************************************************** - * musepack specific functions - *************************************************************************/ - -/* Reads size bytes of data into buffer at ptr. */ -static int32_t mpc_reader_read(void *data, void *ptr, int size) { - mpc_decoder_t *this = (mpc_decoder_t *) data; - - lprintf("mpc_reader_read: size=%d\n", size); - - /* Don't try to read more data than we have */ - if (size > (this->size - this->read)) - size = this->size - this->read; - - /* Copy the data */ - xine_fast_memcpy(ptr, &this->buf[this->read], size); - - /* Update our position in the data buffer */ - this->read += size; - - return size; -} - -/* Seeks to byte position offset. */ -static mpc_bool_t mpc_reader_seek(void *data, int32_t offset) { - mpc_decoder_t *this = (mpc_decoder_t *) data; - - lprintf("mpc_reader_seek: offset=%d\n", offset); - - /* seek is only called when reading the header so we can assume - * that the buffer starts at the start of the file */ - this->read = offset; - - return TRUE; -} - -/* Returns the current byte offset in the stream. */ -static int32_t mpc_reader_tell(void *data) { - lprintf("mpc_reader_tell\n"); - - /* Tell isn't used so just return 0 */ - return 0; -} - -/* Returns the total length of the source stream, in bytes. */ -static int32_t mpc_reader_get_size(void *data) { - mpc_decoder_t *this = (mpc_decoder_t *) data; - - lprintf("mpc_reader_get_size\n"); - - return this->file_size; -} - -/* True if the stream is a seekable stream. */ -static mpc_bool_t mpc_reader_canseek(void *data) { - lprintf("mpc_reader_canseek\n"); - - return TRUE; -} - -/* Convert 32bit float samples into 16bit int samples */ -static inline void float_to_int(float *_f, int16_t *s16, int samples) { - int i; - float f; - for (i = 0; i < samples; i++) { - f = _f[i] * 32767; - if (f > INT16_MAX) f = INT16_MAX; - if (f < INT16_MIN) f = INT16_MIN; - s16[i] = f; - /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */ - } -} - -/* Decode a musepack frame */ -static int mpc_decode_frame (mpc_decoder_t *this) { - float buffer[MPC_DECODER_BUFFER_LENGTH]; - uint32_t frames; - - lprintf("mpd_decode_frame\n"); - - frames = mpc_decoder_decode(&this->decoder, buffer, 0, 0); - - if (frames > 0) { - audio_buffer_t *audio_buffer; - int16_t *int_samples; - - lprintf("got %d samples\n", frames); - - /* Get audio buffer */ - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - audio_buffer->vpts = 0; - audio_buffer->num_frames = frames; - - /* Convert samples */ - int_samples = (int16_t *) audio_buffer->mem; - float_to_int(buffer, int_samples, frames*this->channels); - - /* Output converted samples */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - } - - return frames; -} - -/************************************************************************** - * xine audio plugin functions - *************************************************************************/ - -static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - mpc_decoder_t *this = (mpc_decoder_t *) this_gen; - int err; - - lprintf("mpc_decode_data\n"); - - if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED)) - return; - - /* We don't handle special buffers */ - if (buf->decoder_flags & BUF_FLAG_SPECIAL) - return; - - /* Read header */ - if (buf->decoder_flags & BUF_FLAG_HEADER) { - - lprintf("header\n"); - - /* File size is in decoder_info[0] */ - this->file_size = buf->decoder_info[0]; - - /* Initialise the data accumulation buffer */ - this->buf = xine_xmalloc(INIT_BUFSIZE); - this->buf_max = INIT_BUFSIZE; - this->read = 0; - this->size = 0; - - /* Initialise the reader */ - this->reader.read = mpc_reader_read; - this->reader.seek = mpc_reader_seek; - this->reader.tell = mpc_reader_tell; - this->reader.get_size = mpc_reader_get_size; - this->reader.canseek = mpc_reader_canseek; - this->reader.data = this; - - /* Copy header to buffer */ - xine_fast_memcpy(this->buf, buf->content, buf->size); - this->size = buf->size; - - /* Initialise and read stream info */ - mpc_streaminfo_init(&this->streaminfo); - - if ((err = mpc_streaminfo_read(&this->streaminfo, &this->reader))) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: mpc_streaminfo_read failed: %d\n"), err); - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - - this->sample_rate = this->streaminfo.sample_freq; - this->channels = this->streaminfo.channels; - this->bits_per_sample = 16; - - /* After the header the demuxer starts sending data from an offset - * of 28 bytes */ - this->size = 28; - - /* We need to keep track of the current frame so we now when we've - * reached the end of the stream */ - this->current_frame = 0; - - /* Setup the decoder */ - mpc_decoder_setup(&this->decoder, &this->reader); - this->decoder_ok = 0; - - /* Take this opportunity to initialize stream/meta information */ - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, - "Musepack (libmusepack)"); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, - (int) this->streaminfo.average_bitrate); - - return; - } - - lprintf("data: %u size=%u read=%u\n", buf->size, this->size, this->read); - - /* if the audio output is not open yet, open the audio output */ - if (!this->output_open) { - this->output_open = this->stream->audio_out->open( - this->stream->audio_out, - this->stream, - this->bits_per_sample, - this->sample_rate, - _x_ao_channels2mode(this->channels)); - } - - /* if the audio still isn't open, do not go any further with the decode */ - if (!this->output_open) - return; - - /* If we run out of space in our internal buffer we discard what's - * already been read */ - if (((this->size + buf->size) > this->buf_max) && this->read) { - lprintf("discarding read data\n"); - this->size -= this->read; - memmove(this->buf, &this->buf[this->read], this->size); - this->read = 0; - } - - /* If there still isn't space we have to increase the size of the - * internal buffer */ - if ((this->size + buf->size) > this->buf_max) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "libmusepack: increasing internal buffer size\n"); - this->buf_max += 2*buf->size; - this->buf = realloc(this->buf, this->buf_max); - } - - /* Copy data */ - xine_fast_memcpy(&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - /* Time to decode */ - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - /* Increment frame count */ - if (this->current_frame++ == this->streaminfo.frames) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: data after last frame ignored\n")); - return; - } - - if (!this->decoder_ok) { - /* We require MPC_DECODER_MEMSIZE bytes to initialise the decoder */ - if ((this->size - this->read) >= MPC_DECODER_MEMSIZE) { - lprintf("initialise"); - - if (!mpc_decoder_initialize(&this->decoder, &this->streaminfo)) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: mpc_decoder_initialise failed\n")); - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - - this->decoder_ok = 1; - } else { - /* Not enough data yet */ - return; - } - } - - /* mpc_decoder_decode may cause a read of MPC_DECODER_MEMSIZE/2 bytes so - * make sure we have enough data available */ - if ((this->size - this->read) >= MPC_DECODER_MEMSIZE2) { - lprintf("decoding\n"); - - if ((err = mpc_decode_frame(this)) < 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: mpc_decoder_decode failed: %d\n"), err); - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - } - - /* If we are at the end of the stream we decode the remaining frames as we - * know we'll have enough data */ - if (this->current_frame == this->streaminfo.frames) { - lprintf("flushing buffers\n"); - - do { - if ((err = mpc_decode_frame(this)) < 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("libmusepack: mpc_decoder_decode failed: %d\n"), err); - } - } while (err > 0); - - lprintf("buffers flushed\n"); - } - } -} - -static void mpc_reset (audio_decoder_t *this_gen) { - mpc_decoder_t *this = (mpc_decoder_t *) this_gen; - - this->size = 0; - this->read = 0; -} - -static void mpc_discontinuity (audio_decoder_t *this_gen) { - /* mpc_decoder_t *this = (mpc_decoder_t *) this_gen; */ -} - -static void mpc_dispose (audio_decoder_t *this_gen) { - - mpc_decoder_t *this = (mpc_decoder_t *) this_gen; - - /* close the audio output */ - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - /* free anything that was allocated during operation */ - if (this->buf) - free(this->buf); - - free(this); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - mpc_decoder_t *this ; - - this = (mpc_decoder_t *) xine_xmalloc (sizeof (mpc_decoder_t)); - - /* connect the member functions */ - this->audio_decoder.decode_data = mpc_decode_data; - this->audio_decoder.reset = mpc_reset; - this->audio_decoder.discontinuity = mpc_discontinuity; - this->audio_decoder.dispose = mpc_dispose; - - /* connect the stream */ - this->stream = stream; - - /* audio output is not open at the start */ - this->output_open = 0; - - /* no buffer yet */ - this->buf = NULL; - - /* initialize the basic audio parameters */ - this->channels = 0; - this->sample_rate = 0; - this->bits_per_sample = 0; - - /* return the newly-initialized audio decoder */ - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "mpc"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "mpc: musepack audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this_gen) { - - mpc_class_t *this = (mpc_class_t *)this_gen; - - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - mpc_class_t *this ; - - this = (mpc_class_t *) xine_xmalloc (sizeof (mpc_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_MPC, - 0 -}; - -static const decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* { type, API version, "name", version, special_info, init_function }, */ - { PLUGIN_AUDIO_DECODER, 15, "mpc", XINE_VERSION_CODE, &dec_info_audio, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; - diff --git a/src/libmusepack/xine_musepack_decoder.c b/src/libmusepack/xine_musepack_decoder.c new file mode 100644 index 000000000..26c2eddf5 --- /dev/null +++ b/src/libmusepack/xine_musepack_decoder.c @@ -0,0 +1,471 @@ +/* + * Copyright (C) 2005 the xine project + * + * This file is part of xine, a free 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 + * + * xine interface to libmusepack by James Stembridge + * + * TODO: + * 32bit float output + * Seeking?? + * + * $Id: xine_decoder.c,v 1.10 2007/01/19 02:35:36 dgp85 Exp $ + */ + +#include +#include +#include +#include +#include + +#define LOG_MODULE "mpc_decoder" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "audio_out.h" +#include "buffer.h" +#include "xineutils.h" + +#ifdef HAVE_MPCDEC_MPCDEC_H +# include +#else +# include "musepack/musepack.h" +#endif + +#define MPC_DECODER_MEMSIZE 65536 +#define MPC_DECODER_MEMSIZE2 (MPC_DECODER_MEMSIZE/2) + +#define INIT_BUFSIZE (MPC_DECODER_MEMSIZE*2) + +typedef struct { + audio_decoder_class_t decoder_class; +} mpc_class_t; + +typedef struct mpc_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + int sample_rate; /* audio sample rate */ + int bits_per_sample; /* bits/sample, usually 8 or 16 */ + int channels; /* 1 or 2, usually */ + + int output_open; /* flag to indicate audio is ready */ + + unsigned char *buf; /* data accumulation buffer */ + unsigned int buf_max; /* maximum size of buf */ + unsigned int read; /* size of accum. data already read */ + unsigned int size; /* size of accumulated data in buf */ + + mpc_reader reader; + mpc_streaminfo streaminfo; + mpc_decoder decoder; + + int decoder_ok; + unsigned int current_frame; + + int32_t file_size; + +} mpc_decoder_t; + + +/************************************************************************** + * musepack specific functions + *************************************************************************/ + +/* Reads size bytes of data into buffer at ptr. */ +static int32_t mpc_reader_read(void *data, void *ptr, int size) { + mpc_decoder_t *this = (mpc_decoder_t *) data; + + lprintf("mpc_reader_read: size=%d\n", size); + + /* Don't try to read more data than we have */ + if (size > (this->size - this->read)) + size = this->size - this->read; + + /* Copy the data */ + xine_fast_memcpy(ptr, &this->buf[this->read], size); + + /* Update our position in the data buffer */ + this->read += size; + + return size; +} + +/* Seeks to byte position offset. */ +static mpc_bool_t mpc_reader_seek(void *data, int32_t offset) { + mpc_decoder_t *this = (mpc_decoder_t *) data; + + lprintf("mpc_reader_seek: offset=%d\n", offset); + + /* seek is only called when reading the header so we can assume + * that the buffer starts at the start of the file */ + this->read = offset; + + return TRUE; +} + +/* Returns the current byte offset in the stream. */ +static int32_t mpc_reader_tell(void *data) { + lprintf("mpc_reader_tell\n"); + + /* Tell isn't used so just return 0 */ + return 0; +} + +/* Returns the total length of the source stream, in bytes. */ +static int32_t mpc_reader_get_size(void *data) { + mpc_decoder_t *this = (mpc_decoder_t *) data; + + lprintf("mpc_reader_get_size\n"); + + return this->file_size; +} + +/* True if the stream is a seekable stream. */ +static mpc_bool_t mpc_reader_canseek(void *data) { + lprintf("mpc_reader_canseek\n"); + + return TRUE; +} + +/* Convert 32bit float samples into 16bit int samples */ +static inline void float_to_int(float *_f, int16_t *s16, int samples) { + int i; + float f; + for (i = 0; i < samples; i++) { + f = _f[i] * 32767; + if (f > INT16_MAX) f = INT16_MAX; + if (f < INT16_MIN) f = INT16_MIN; + s16[i] = f; + /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */ + } +} + +/* Decode a musepack frame */ +static int mpc_decode_frame (mpc_decoder_t *this) { + float buffer[MPC_DECODER_BUFFER_LENGTH]; + uint32_t frames; + + lprintf("mpd_decode_frame\n"); + + frames = mpc_decoder_decode(&this->decoder, buffer, 0, 0); + + if (frames > 0) { + audio_buffer_t *audio_buffer; + int16_t *int_samples; + + lprintf("got %d samples\n", frames); + + /* Get audio buffer */ + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + audio_buffer->vpts = 0; + audio_buffer->num_frames = frames; + + /* Convert samples */ + int_samples = (int16_t *) audio_buffer->mem; + float_to_int(buffer, int_samples, frames*this->channels); + + /* Output converted samples */ + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + } + + return frames; +} + +/************************************************************************** + * xine audio plugin functions + *************************************************************************/ + +static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + mpc_decoder_t *this = (mpc_decoder_t *) this_gen; + int err; + + lprintf("mpc_decode_data\n"); + + if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED)) + return; + + /* We don't handle special buffers */ + if (buf->decoder_flags & BUF_FLAG_SPECIAL) + return; + + /* Read header */ + if (buf->decoder_flags & BUF_FLAG_HEADER) { + + lprintf("header\n"); + + /* File size is in decoder_info[0] */ + this->file_size = buf->decoder_info[0]; + + /* Initialise the data accumulation buffer */ + this->buf = xine_xmalloc(INIT_BUFSIZE); + this->buf_max = INIT_BUFSIZE; + this->read = 0; + this->size = 0; + + /* Initialise the reader */ + this->reader.read = mpc_reader_read; + this->reader.seek = mpc_reader_seek; + this->reader.tell = mpc_reader_tell; + this->reader.get_size = mpc_reader_get_size; + this->reader.canseek = mpc_reader_canseek; + this->reader.data = this; + + /* Copy header to buffer */ + xine_fast_memcpy(this->buf, buf->content, buf->size); + this->size = buf->size; + + /* Initialise and read stream info */ + mpc_streaminfo_init(&this->streaminfo); + + if ((err = mpc_streaminfo_read(&this->streaminfo, &this->reader))) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("libmusepack: mpc_streaminfo_read failed: %d\n"), err); + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + + this->sample_rate = this->streaminfo.sample_freq; + this->channels = this->streaminfo.channels; + this->bits_per_sample = 16; + + /* After the header the demuxer starts sending data from an offset + * of 28 bytes */ + this->size = 28; + + /* We need to keep track of the current frame so we now when we've + * reached the end of the stream */ + this->current_frame = 0; + + /* Setup the decoder */ + mpc_decoder_setup(&this->decoder, &this->reader); + this->decoder_ok = 0; + + /* Take this opportunity to initialize stream/meta information */ + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, + "Musepack (libmusepack)"); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, + (int) this->streaminfo.average_bitrate); + + return; + } + + lprintf("data: %u size=%u read=%u\n", buf->size, this->size, this->read); + + /* if the audio output is not open yet, open the audio output */ + if (!this->output_open) { + this->output_open = this->stream->audio_out->open( + this->stream->audio_out, + this->stream, + this->bits_per_sample, + this->sample_rate, + _x_ao_channels2mode(this->channels)); + } + + /* if the audio still isn't open, do not go any further with the decode */ + if (!this->output_open) + return; + + /* If we run out of space in our internal buffer we discard what's + * already been read */ + if (((this->size + buf->size) > this->buf_max) && this->read) { + lprintf("discarding read data\n"); + this->size -= this->read; + memmove(this->buf, &this->buf[this->read], this->size); + this->read = 0; + } + + /* If there still isn't space we have to increase the size of the + * internal buffer */ + if ((this->size + buf->size) > this->buf_max) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "libmusepack: increasing internal buffer size\n"); + this->buf_max += 2*buf->size; + this->buf = realloc(this->buf, this->buf_max); + } + + /* Copy data */ + xine_fast_memcpy(&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + /* Time to decode */ + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + /* Increment frame count */ + if (this->current_frame++ == this->streaminfo.frames) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("libmusepack: data after last frame ignored\n")); + return; + } + + if (!this->decoder_ok) { + /* We require MPC_DECODER_MEMSIZE bytes to initialise the decoder */ + if ((this->size - this->read) >= MPC_DECODER_MEMSIZE) { + lprintf("initialise"); + + if (!mpc_decoder_initialize(&this->decoder, &this->streaminfo)) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("libmusepack: mpc_decoder_initialise failed\n")); + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + + this->decoder_ok = 1; + } else { + /* Not enough data yet */ + return; + } + } + + /* mpc_decoder_decode may cause a read of MPC_DECODER_MEMSIZE/2 bytes so + * make sure we have enough data available */ + if ((this->size - this->read) >= MPC_DECODER_MEMSIZE2) { + lprintf("decoding\n"); + + if ((err = mpc_decode_frame(this)) < 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("libmusepack: mpc_decoder_decode failed: %d\n"), err); + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + } + + /* If we are at the end of the stream we decode the remaining frames as we + * know we'll have enough data */ + if (this->current_frame == this->streaminfo.frames) { + lprintf("flushing buffers\n"); + + do { + if ((err = mpc_decode_frame(this)) < 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("libmusepack: mpc_decoder_decode failed: %d\n"), err); + } + } while (err > 0); + + lprintf("buffers flushed\n"); + } + } +} + +static void mpc_reset (audio_decoder_t *this_gen) { + mpc_decoder_t *this = (mpc_decoder_t *) this_gen; + + this->size = 0; + this->read = 0; +} + +static void mpc_discontinuity (audio_decoder_t *this_gen) { + /* mpc_decoder_t *this = (mpc_decoder_t *) this_gen; */ +} + +static void mpc_dispose (audio_decoder_t *this_gen) { + + mpc_decoder_t *this = (mpc_decoder_t *) this_gen; + + /* close the audio output */ + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + /* free anything that was allocated during operation */ + if (this->buf) + free(this->buf); + + free(this); +} + +static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + mpc_decoder_t *this ; + + this = (mpc_decoder_t *) xine_xmalloc (sizeof (mpc_decoder_t)); + + /* connect the member functions */ + this->audio_decoder.decode_data = mpc_decode_data; + this->audio_decoder.reset = mpc_reset; + this->audio_decoder.discontinuity = mpc_discontinuity; + this->audio_decoder.dispose = mpc_dispose; + + /* connect the stream */ + this->stream = stream; + + /* audio output is not open at the start */ + this->output_open = 0; + + /* no buffer yet */ + this->buf = NULL; + + /* initialize the basic audio parameters */ + this->channels = 0; + this->sample_rate = 0; + this->bits_per_sample = 0; + + /* return the newly-initialized audio decoder */ + return &this->audio_decoder; +} + +static char *get_identifier (audio_decoder_class_t *this) { + return "mpc"; +} + +static char *get_description (audio_decoder_class_t *this) { + return "mpc: musepack audio decoder plugin"; +} + +static void dispose_class (audio_decoder_class_t *this_gen) { + + mpc_class_t *this = (mpc_class_t *)this_gen; + + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + mpc_class_t *this ; + + this = (mpc_class_t *) xine_xmalloc (sizeof (mpc_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + return this; +} + +static uint32_t audio_types[] = { + BUF_AUDIO_MPC, + 0 +}; + +static const decoder_info_t dec_info_audio = { + audio_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* { type, API version, "name", version, special_info, init_function }, */ + { PLUGIN_AUDIO_DECODER, 15, "mpc", XINE_VERSION_CODE, &dec_info_audio, &init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; + -- cgit v1.2.3 From 4faff7cf17d8e46c309ed53facf882f9d926ae7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:43:18 +0200 Subject: Rename xine_decoder.c to xine_cc_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libspucc/xine_decoder.c => src/libspucc/xine_cc_decoder.c --- src/libspucc/Makefile.am | 2 +- src/libspucc/xine_cc_decoder.c | 369 +++++++++++++++++++++++++++++++++++++++++ src/libspucc/xine_decoder.c | 369 ----------------------------------------- 3 files changed, 370 insertions(+), 370 deletions(-) create mode 100644 src/libspucc/xine_cc_decoder.c delete mode 100644 src/libspucc/xine_decoder.c (limited to 'src') diff --git a/src/libspucc/Makefile.am b/src/libspucc/Makefile.am index fff0ab47c..ec12c1bc7 100644 --- a/src/libspucc/Makefile.am +++ b/src/libspucc/Makefile.am @@ -4,7 +4,7 @@ libdir = $(XINE_PLUGINDIR) lib_LTLIBRARIES = xineplug_decode_spucc.la -xineplug_decode_spucc_la_SOURCES = cc_decoder.c xine_decoder.c +xineplug_decode_spucc_la_SOURCES = cc_decoder.c xine_cc_decoder.c xineplug_decode_spucc_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -fno-strict-aliasing xineplug_decode_spucc_la_LIBADD = $(XINE_LIB) xineplug_decode_spucc_la_LDFLAGS = -avoid-version -module diff --git a/src/libspucc/xine_cc_decoder.c b/src/libspucc/xine_cc_decoder.c new file mode 100644 index 000000000..1a32274f6 --- /dev/null +++ b/src/libspucc/xine_cc_decoder.c @@ -0,0 +1,369 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.34 2006/07/10 22:08:30 dgp85 Exp $ + * + * closed caption spu decoder. receive data by events. + * + */ + +#include +#include +#include + +#include "buffer.h" +#include "xine_internal.h" +#include "xineutils.h" +#include "cc_decoder.h" + +/* +#define LOG_DEBUG 1 +*/ + +typedef struct spucc_decoder_s { + spu_decoder_t spu_decoder; + + xine_stream_t *stream; + + /* closed captioning decoder state */ + cc_decoder_t *ccdec; + /* true if ccdec has been initialized */ + int cc_open; + + /* closed captioning decoder configuration and intrinsics */ + cc_state_t cc_state; + /* this is to detect configuration changes */ + int config_version; + + /* video dimensions captured in frame change events */ + int video_width; + int video_height; + + /* events will be sent here */ + xine_event_queue_t *queue; + +} spucc_decoder_t; + + +/*------------------- general utility functions ----------------------------*/ + +static void copy_str(char *d, const char *s, size_t maxbytes) +{ + strncpy(d, s, maxbytes - 1); + d[maxbytes - 1] = '\0'; +} + + +/*------------------- private methods --------------------------------------*/ + +static void spucc_update_intrinsics(spucc_decoder_t *this) +{ +#ifdef LOG_DEBUG + printf("spucc: update_intrinsics\n"); +#endif + + if (this->cc_open) + cc_renderer_update_cfg(this->cc_state.renderer, this->video_width, + this->video_height); +} + +static void spucc_do_close(spucc_decoder_t *this) +{ + if (this->cc_open) { +#ifdef LOG_DEBUG + printf("spucc: close\n"); +#endif + cc_decoder_close(this->ccdec); + cc_renderer_close(this->cc_state.renderer); + this->cc_open = 0; + } +} + +static void spucc_do_init (spucc_decoder_t *this) +{ + if (! this->cc_open) { +#ifdef LOG_DEBUG + printf("spucc: init\n"); +#endif + /* initialize caption renderer */ + this->cc_state.renderer = cc_renderer_open(this->stream->osd_renderer, + this->stream->metronom, + &this->cc_state, + this->video_width, + this->video_height); + spucc_update_intrinsics(this); + /* initialize CC decoder */ + this->ccdec = cc_decoder_open(&this->cc_state); + this->cc_open = 1; + } +} + + +/*----------------- configuration listeners --------------------------------*/ + +static void spucc_cfg_enable_change(void *this_gen, xine_cfg_entry_t *value) +{ + spucc_class_t *this = (spucc_class_t *) this_gen; + cc_config_t *cc_cfg = &this->cc_cfg; + + cc_cfg->cc_enabled = value->num_value; +#ifdef LOG_DEBUG + printf("spucc: closed captions are now %s.\n", cc_cfg->cc_enabled? + "enabled" : "disabled"); +#endif + cc_cfg->config_version++; +} + + +static void spucc_cfg_scheme_change(void *this_gen, xine_cfg_entry_t *value) +{ + spucc_class_t *this = (spucc_class_t *) this_gen; + cc_config_t *cc_cfg = &this->cc_cfg; + + cc_cfg->cc_scheme = value->num_value; +#ifdef LOG_DEBUG + printf("spucc: closed captioning scheme is now %s.\n", + cc_schemes[cc_cfg->cc_scheme]); +#endif + cc_cfg->config_version++; +} + + +static void spucc_font_change(void *this_gen, xine_cfg_entry_t *value) +{ + spucc_class_t *this = (spucc_class_t *) this_gen; + cc_config_t *cc_cfg = &this->cc_cfg; + char *font; + + if (strcmp(value->key, "subtitles.closedcaption.font") == 0) + font = cc_cfg->font; + else + font = cc_cfg->italic_font; + + copy_str(font, value->str_value, CC_FONT_MAX); +#ifdef LOG_DEBUG + printf("spucc: changing %s to font %s\n", value->key, font); +#endif + cc_cfg->config_version++; +} + + +static void spucc_num_change(void *this_gen, xine_cfg_entry_t *value) +{ + spucc_class_t *this = (spucc_class_t *) this_gen; + cc_config_t *cc_cfg = &this->cc_cfg; + int *num; + + if (strcmp(value->key, "subtitles.closedcaption.font_size") == 0) + num = &cc_cfg->font_size; + else + num = &cc_cfg->center; + + *num = value->num_value; +#ifdef LOG_DEBUG + printf("spucc: changing %s to %d\n", value->key, *num); +#endif + cc_cfg->config_version++; +} + + +static void spucc_register_cfg_vars(spucc_class_t *this, + config_values_t *xine_cfg) { + cc_config_t *cc_vars = &this->cc_cfg; + + cc_vars->cc_enabled = xine_cfg->register_bool(xine_cfg, + "subtitles.closedcaption.enabled", 0, + _("display closed captions in MPEG-2 streams"), + _("Closed Captions are subtitles mostly meant " + "to help the hearing impaired."), + 0, spucc_cfg_enable_change, this); + + cc_vars->cc_scheme = xine_cfg->register_enum(xine_cfg, + "subtitles.closedcaption.scheme", 0, + cc_schemes, + _("closed-captioning foreground/background scheme"), + _("Choose your favourite rendering of the closed " + "captions."), + 10, spucc_cfg_scheme_change, this); + + copy_str(cc_vars->font, + xine_cfg->register_string(xine_cfg, "subtitles.closedcaption.font", "cc", + _("standard closed captioning font"), + _("Choose the font for standard closed captions text."), + 20, spucc_font_change, this), + CC_FONT_MAX); + + copy_str(cc_vars->italic_font, + xine_cfg->register_string(xine_cfg, "subtitles.closedcaption.italic_font", "cci", + _("italic closed captioning font"), + _("Choose the font for italic closed captions text."), + 20, spucc_font_change, this), + CC_FONT_MAX); + + cc_vars->font_size = xine_cfg->register_num(xine_cfg, "subtitles.closedcaption.font_size", + 24, + _("closed captioning font size"), + _("Choose the font size for closed captions text."), + 10, spucc_num_change, this); + + cc_vars->center = xine_cfg->register_bool(xine_cfg, "subtitles.closedcaption.center", 1, + _("center-adjust closed captions"), + _("When enabled, closed captions will be positioned " + "by the center of the individual lines."), + 20, spucc_num_change, this); +} + + +/* called when the video frame size changes */ +static void spucc_notify_frame_change(spucc_decoder_t *this, + int width, int height) { +#ifdef LOG_DEBUG + printf("spucc: new frame size: %dx%d\n", width, height); +#endif + + this->video_width = width; + this->video_height = height; + spucc_update_intrinsics(this); +} + + +/*------------------- implementation of spudec interface -------------------*/ + +static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { + spucc_decoder_t *this = (spucc_decoder_t *) this_gen; + xine_event_t *event; + + while ((event = xine_event_get(this->queue))) { + switch (event->type) { + case XINE_EVENT_FRAME_FORMAT_CHANGE: + { + xine_format_change_data_t *frame_change = + (xine_format_change_data_t *)event->data; + + spucc_notify_frame_change(this, frame_change->width, + frame_change->height); + } + break; + } + xine_event_free(event); + } + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) { + } else { + + if (this->cc_state.cc_cfg->config_version > this->config_version) { + spucc_update_intrinsics(this); + if (!this->cc_state.cc_cfg->cc_enabled) + spucc_do_close(this); + this->config_version = this->cc_state.cc_cfg->config_version; + } + + if (this->cc_state.cc_cfg->cc_enabled) { + if( !this->cc_open ) + spucc_do_init (this); + if(this->cc_state.can_cc) { + decode_cc(this->ccdec, buf->content, buf->size, + buf->pts); + } + } + } +} + +static void spudec_reset (spu_decoder_t *this_gen) { +} + +static void spudec_discontinuity (spu_decoder_t *this_gen) { +} + +static void spudec_dispose (spu_decoder_t *this_gen) { + spucc_decoder_t *this = (spucc_decoder_t *) this_gen; + + spucc_do_close(this); + xine_event_dispose_queue(this->queue); + free (this); +} + + +static spu_decoder_t *spudec_open_plugin (spu_decoder_class_t *class, xine_stream_t *stream) { + + spucc_decoder_t *this ; + + this = (spucc_decoder_t *) xine_xmalloc (sizeof (spucc_decoder_t)); + + this->spu_decoder.decode_data = spudec_decode_data; + this->spu_decoder.reset = spudec_reset; + this->spu_decoder.discontinuity = spudec_discontinuity; + this->spu_decoder.dispose = spudec_dispose; + this->spu_decoder.get_interact_info = NULL; + this->spu_decoder.set_button = NULL; + + this->stream = stream; + this->queue = xine_event_new_queue(stream); + this->cc_state.cc_cfg = &((spucc_class_t *)class)->cc_cfg; + this->config_version = 0; + this->cc_open = 0; + + cc_decoder_init(); + + return &this->spu_decoder; +} + +static char *spudec_get_identifier(spu_decoder_class_t *class) { + return "spucc"; +} + +static char *spudec_get_description(spu_decoder_class_t *class) { + return "closed caption decoder plugin"; +} + +static void spudec_class_dispose(spu_decoder_class_t *class) { + free(class); +} + + +static void *init_spu_decoder_plugin (xine_t *xine, void *data) { + + spucc_class_t *this ; + + this = (spucc_class_t *) xine_xmalloc (sizeof (spucc_class_t)); + + this->spu_class.open_plugin = spudec_open_plugin; + this->spu_class.get_identifier = spudec_get_identifier; + this->spu_class.get_description = spudec_get_description; + this->spu_class.dispose = spudec_class_dispose; + + spucc_register_cfg_vars(this, xine->config); + this->cc_cfg.config_version = 0; + + return &this->spu_class; +} + +/* plugin catalog information */ +static uint32_t supported_types[] = { BUF_SPU_CC, 0 }; + +static const decoder_info_t spudec_info = { + supported_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_SPU_DECODER, 16, "spucc", XINE_VERSION_CODE, &spudec_info, &init_spu_decoder_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/libspucc/xine_decoder.c b/src/libspucc/xine_decoder.c deleted file mode 100644 index 1a32274f6..000000000 --- a/src/libspucc/xine_decoder.c +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.34 2006/07/10 22:08:30 dgp85 Exp $ - * - * closed caption spu decoder. receive data by events. - * - */ - -#include -#include -#include - -#include "buffer.h" -#include "xine_internal.h" -#include "xineutils.h" -#include "cc_decoder.h" - -/* -#define LOG_DEBUG 1 -*/ - -typedef struct spucc_decoder_s { - spu_decoder_t spu_decoder; - - xine_stream_t *stream; - - /* closed captioning decoder state */ - cc_decoder_t *ccdec; - /* true if ccdec has been initialized */ - int cc_open; - - /* closed captioning decoder configuration and intrinsics */ - cc_state_t cc_state; - /* this is to detect configuration changes */ - int config_version; - - /* video dimensions captured in frame change events */ - int video_width; - int video_height; - - /* events will be sent here */ - xine_event_queue_t *queue; - -} spucc_decoder_t; - - -/*------------------- general utility functions ----------------------------*/ - -static void copy_str(char *d, const char *s, size_t maxbytes) -{ - strncpy(d, s, maxbytes - 1); - d[maxbytes - 1] = '\0'; -} - - -/*------------------- private methods --------------------------------------*/ - -static void spucc_update_intrinsics(spucc_decoder_t *this) -{ -#ifdef LOG_DEBUG - printf("spucc: update_intrinsics\n"); -#endif - - if (this->cc_open) - cc_renderer_update_cfg(this->cc_state.renderer, this->video_width, - this->video_height); -} - -static void spucc_do_close(spucc_decoder_t *this) -{ - if (this->cc_open) { -#ifdef LOG_DEBUG - printf("spucc: close\n"); -#endif - cc_decoder_close(this->ccdec); - cc_renderer_close(this->cc_state.renderer); - this->cc_open = 0; - } -} - -static void spucc_do_init (spucc_decoder_t *this) -{ - if (! this->cc_open) { -#ifdef LOG_DEBUG - printf("spucc: init\n"); -#endif - /* initialize caption renderer */ - this->cc_state.renderer = cc_renderer_open(this->stream->osd_renderer, - this->stream->metronom, - &this->cc_state, - this->video_width, - this->video_height); - spucc_update_intrinsics(this); - /* initialize CC decoder */ - this->ccdec = cc_decoder_open(&this->cc_state); - this->cc_open = 1; - } -} - - -/*----------------- configuration listeners --------------------------------*/ - -static void spucc_cfg_enable_change(void *this_gen, xine_cfg_entry_t *value) -{ - spucc_class_t *this = (spucc_class_t *) this_gen; - cc_config_t *cc_cfg = &this->cc_cfg; - - cc_cfg->cc_enabled = value->num_value; -#ifdef LOG_DEBUG - printf("spucc: closed captions are now %s.\n", cc_cfg->cc_enabled? - "enabled" : "disabled"); -#endif - cc_cfg->config_version++; -} - - -static void spucc_cfg_scheme_change(void *this_gen, xine_cfg_entry_t *value) -{ - spucc_class_t *this = (spucc_class_t *) this_gen; - cc_config_t *cc_cfg = &this->cc_cfg; - - cc_cfg->cc_scheme = value->num_value; -#ifdef LOG_DEBUG - printf("spucc: closed captioning scheme is now %s.\n", - cc_schemes[cc_cfg->cc_scheme]); -#endif - cc_cfg->config_version++; -} - - -static void spucc_font_change(void *this_gen, xine_cfg_entry_t *value) -{ - spucc_class_t *this = (spucc_class_t *) this_gen; - cc_config_t *cc_cfg = &this->cc_cfg; - char *font; - - if (strcmp(value->key, "subtitles.closedcaption.font") == 0) - font = cc_cfg->font; - else - font = cc_cfg->italic_font; - - copy_str(font, value->str_value, CC_FONT_MAX); -#ifdef LOG_DEBUG - printf("spucc: changing %s to font %s\n", value->key, font); -#endif - cc_cfg->config_version++; -} - - -static void spucc_num_change(void *this_gen, xine_cfg_entry_t *value) -{ - spucc_class_t *this = (spucc_class_t *) this_gen; - cc_config_t *cc_cfg = &this->cc_cfg; - int *num; - - if (strcmp(value->key, "subtitles.closedcaption.font_size") == 0) - num = &cc_cfg->font_size; - else - num = &cc_cfg->center; - - *num = value->num_value; -#ifdef LOG_DEBUG - printf("spucc: changing %s to %d\n", value->key, *num); -#endif - cc_cfg->config_version++; -} - - -static void spucc_register_cfg_vars(spucc_class_t *this, - config_values_t *xine_cfg) { - cc_config_t *cc_vars = &this->cc_cfg; - - cc_vars->cc_enabled = xine_cfg->register_bool(xine_cfg, - "subtitles.closedcaption.enabled", 0, - _("display closed captions in MPEG-2 streams"), - _("Closed Captions are subtitles mostly meant " - "to help the hearing impaired."), - 0, spucc_cfg_enable_change, this); - - cc_vars->cc_scheme = xine_cfg->register_enum(xine_cfg, - "subtitles.closedcaption.scheme", 0, - cc_schemes, - _("closed-captioning foreground/background scheme"), - _("Choose your favourite rendering of the closed " - "captions."), - 10, spucc_cfg_scheme_change, this); - - copy_str(cc_vars->font, - xine_cfg->register_string(xine_cfg, "subtitles.closedcaption.font", "cc", - _("standard closed captioning font"), - _("Choose the font for standard closed captions text."), - 20, spucc_font_change, this), - CC_FONT_MAX); - - copy_str(cc_vars->italic_font, - xine_cfg->register_string(xine_cfg, "subtitles.closedcaption.italic_font", "cci", - _("italic closed captioning font"), - _("Choose the font for italic closed captions text."), - 20, spucc_font_change, this), - CC_FONT_MAX); - - cc_vars->font_size = xine_cfg->register_num(xine_cfg, "subtitles.closedcaption.font_size", - 24, - _("closed captioning font size"), - _("Choose the font size for closed captions text."), - 10, spucc_num_change, this); - - cc_vars->center = xine_cfg->register_bool(xine_cfg, "subtitles.closedcaption.center", 1, - _("center-adjust closed captions"), - _("When enabled, closed captions will be positioned " - "by the center of the individual lines."), - 20, spucc_num_change, this); -} - - -/* called when the video frame size changes */ -static void spucc_notify_frame_change(spucc_decoder_t *this, - int width, int height) { -#ifdef LOG_DEBUG - printf("spucc: new frame size: %dx%d\n", width, height); -#endif - - this->video_width = width; - this->video_height = height; - spucc_update_intrinsics(this); -} - - -/*------------------- implementation of spudec interface -------------------*/ - -static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { - spucc_decoder_t *this = (spucc_decoder_t *) this_gen; - xine_event_t *event; - - while ((event = xine_event_get(this->queue))) { - switch (event->type) { - case XINE_EVENT_FRAME_FORMAT_CHANGE: - { - xine_format_change_data_t *frame_change = - (xine_format_change_data_t *)event->data; - - spucc_notify_frame_change(this, frame_change->width, - frame_change->height); - } - break; - } - xine_event_free(event); - } - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - } else { - - if (this->cc_state.cc_cfg->config_version > this->config_version) { - spucc_update_intrinsics(this); - if (!this->cc_state.cc_cfg->cc_enabled) - spucc_do_close(this); - this->config_version = this->cc_state.cc_cfg->config_version; - } - - if (this->cc_state.cc_cfg->cc_enabled) { - if( !this->cc_open ) - spucc_do_init (this); - if(this->cc_state.can_cc) { - decode_cc(this->ccdec, buf->content, buf->size, - buf->pts); - } - } - } -} - -static void spudec_reset (spu_decoder_t *this_gen) { -} - -static void spudec_discontinuity (spu_decoder_t *this_gen) { -} - -static void spudec_dispose (spu_decoder_t *this_gen) { - spucc_decoder_t *this = (spucc_decoder_t *) this_gen; - - spucc_do_close(this); - xine_event_dispose_queue(this->queue); - free (this); -} - - -static spu_decoder_t *spudec_open_plugin (spu_decoder_class_t *class, xine_stream_t *stream) { - - spucc_decoder_t *this ; - - this = (spucc_decoder_t *) xine_xmalloc (sizeof (spucc_decoder_t)); - - this->spu_decoder.decode_data = spudec_decode_data; - this->spu_decoder.reset = spudec_reset; - this->spu_decoder.discontinuity = spudec_discontinuity; - this->spu_decoder.dispose = spudec_dispose; - this->spu_decoder.get_interact_info = NULL; - this->spu_decoder.set_button = NULL; - - this->stream = stream; - this->queue = xine_event_new_queue(stream); - this->cc_state.cc_cfg = &((spucc_class_t *)class)->cc_cfg; - this->config_version = 0; - this->cc_open = 0; - - cc_decoder_init(); - - return &this->spu_decoder; -} - -static char *spudec_get_identifier(spu_decoder_class_t *class) { - return "spucc"; -} - -static char *spudec_get_description(spu_decoder_class_t *class) { - return "closed caption decoder plugin"; -} - -static void spudec_class_dispose(spu_decoder_class_t *class) { - free(class); -} - - -static void *init_spu_decoder_plugin (xine_t *xine, void *data) { - - spucc_class_t *this ; - - this = (spucc_class_t *) xine_xmalloc (sizeof (spucc_class_t)); - - this->spu_class.open_plugin = spudec_open_plugin; - this->spu_class.get_identifier = spudec_get_identifier; - this->spu_class.get_description = spudec_get_description; - this->spu_class.dispose = spudec_class_dispose; - - spucc_register_cfg_vars(this, xine->config); - this->cc_cfg.config_version = 0; - - return &this->spu_class; -} - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_SPU_CC, 0 }; - -static const decoder_info_t spudec_info = { - supported_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_SPU_DECODER, 16, "spucc", XINE_VERSION_CODE, &spudec_info, &init_spu_decoder_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; -- cgit v1.2.3 From 68761b9f3158dda6345060b4cb91cf77cb4fa52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:44:16 +0200 Subject: Rename xine_decoder.c to xine_cmml_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libspucmml/xine_decoder.c => src/libspucmml/xine_cmml_decoder.c --- src/libspucmml/Makefile.am | 8 +- src/libspucmml/xine_cmml_decoder.c | 552 +++++++++++++++++++++++++++++++++++++ src/libspucmml/xine_decoder.c | 552 ------------------------------------- 3 files changed, 555 insertions(+), 557 deletions(-) create mode 100644 src/libspucmml/xine_cmml_decoder.c delete mode 100644 src/libspucmml/xine_decoder.c (limited to 'src') diff --git a/src/libspucmml/Makefile.am b/src/libspucmml/Makefile.am index cf9095399..ac2970482 100644 --- a/src/libspucmml/Makefile.am +++ b/src/libspucmml/Makefile.am @@ -1,10 +1,8 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) +xineplug_LTLIBRARIES = xineplug_decode_spucmml.la -lib_LTLIBRARIES = xineplug_decode_spucmml.la - -xineplug_decode_spucmml_la_SOURCES = xine_decoder.c +xineplug_decode_spucmml_la_SOURCES = xine_cmml_decoder.c xineplug_decode_spucmml_la_LIBADD = $(XINE_LIB) xineplug_decode_spucmml_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_spucmml_la_LDFLAGS = -avoid-version -module +xineplug_decode_spucmml_la_LDFLAGS = $(xineplug_ldflags) diff --git a/src/libspucmml/xine_cmml_decoder.c b/src/libspucmml/xine_cmml_decoder.c new file mode 100644 index 000000000..13cb6c066 --- /dev/null +++ b/src/libspucmml/xine_cmml_decoder.c @@ -0,0 +1,552 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.8 2006/07/10 22:08:30 dgp85 Exp $ + * + */ + +#define LOG_MODULE "libspucmml" +#define LOG_VERBOSE +/* +#define LOG +*/ +#define LOG_OSD 0 +#define LOG_SCHEDULING 0 +#define LOG_WIDTH 0 + +#define SUB_BUFSIZE 1024 +#define SUB_MAX_TEXT 5 + +#include "xine_internal.h" + +typedef enum { + SUBTITLE_SIZE_SMALL = 0, + SUBTITLE_SIZE_NORMAL, + SUBTITLE_SIZE_LARGE, + + SUBTITLE_SIZE_NUM /* number of values in enum */ +} subtitle_size; + + +typedef struct spucmml_class_s { + spu_decoder_class_t class; + char *src_encoding; /* encoding of subtitle file */ + xine_t *xine; + +} spucmml_class_t; + + +typedef struct cmml_anchor_s { + char *text; + char *href; +} cmml_anchor_t; + + +typedef struct spucmml_decoder_s { + spu_decoder_t spu_decoder; + + spucmml_class_t *class; + xine_stream_t *stream; + + xine_event_queue_t *event_queue; + + int lines; + char text[SUB_MAX_TEXT][SUB_BUFSIZE]; + + int cached_width; /* frame width */ + int cached_height; /* frame height */ + int64_t cached_img_duration; + int font_size; + int line_height; + int master_started; + int slave_started; + + char *font; /* subtitle font */ + subtitle_size subtitle_size; /* size of subtitles */ + int vertical_offset; + + osd_object_t *osd; + + cmml_anchor_t current_anchor; +} spucmml_decoder_t; + + +static void video_frame_format_change_callback (void *user_data, const xine_event_t *event); + + +static void update_font_size (spucmml_decoder_t *this) { + static int sizes[SUBTITLE_SIZE_NUM][4] = { + { 16, 16, 16, 20 }, /* SUBTITLE_SIZE_SMALL */ + { 16, 16, 20, 24 }, /* SUBTITLE_SIZE_NORMAL */ + { 16, 20, 24, 32 }, /* SUBTITLE_SIZE_LARGE */ + }; + + int *vec = sizes[this->subtitle_size]; + int y; + + if( this->cached_width >= 512 ) + this->font_size = vec[3]; + else if( this->cached_width >= 384 ) + this->font_size = vec[2]; + else if( this->cached_width >= 320 ) + this->font_size = vec[1]; + else + this->font_size = vec[0]; + + this->line_height = this->font_size + 10; + + y = this->cached_height - (SUB_MAX_TEXT * this->line_height) - 5; + + if(((y - this->vertical_offset) >= 0) && ((y - this->vertical_offset) <= this->cached_height)) + y -= this->vertical_offset; + + /* TODO: we should move this stuff below into another function */ + + if (this->osd) + this->stream->osd_renderer->free_object (this->osd); + + llprintf (LOG_OSD, + "pre new_object: osd=%p, osd_renderer=%p, width=%d, height=%d\n", + this->osd, + this->stream->osd_renderer, + this->cached_width, + SUB_MAX_TEXT * this->line_height); + + this->osd = this->stream->osd_renderer->new_object (this->stream->osd_renderer, + this->cached_width, SUB_MAX_TEXT * this->line_height); + + llprintf (LOG_OSD, "post new_object: osd is %p\n", this->osd); + + if(this->stream->osd_renderer) { + this->stream->osd_renderer->set_font (this->osd, this->font, this->font_size); + this->stream->osd_renderer->set_position (this->osd, 0, y); + } +} + +static int get_width(spucmml_decoder_t *this, char* text) { + size_t i=0; + int width=0,w,dummy; + char letter[2]={0, 0}; + + while (i<=strlen(text)) { + switch (text[i]) { + case '<': + if (!strncmp("", text+i, 3)) { + /*Do somethink to enable BOLD typeface*/ + i=i+3; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable BOLD typeface*/ + i=i+4; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to enable italics typeface*/ + i=i+3; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable italics typeface*/ + i=i+4; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable typing + fixme - no teststreams*/ + i=i+6; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to enable typing + fixme - no teststreams*/ + i=i+7; + break; + } + default: + letter[0]=text[i]; + this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); + width=width+w; + i++; + } + } + + llprintf(LOG_WIDTH, "get_width returning width of %d\n", width); + + return width; +} + +static void render_line(spucmml_decoder_t *this, int x, int y, char* text) { + size_t i=0; + int w,dummy; + char letter[2]={0,0}; + + while (i<=strlen(text)) { + letter[0]=text[i]; + this->stream->osd_renderer->render_text(this->osd, x, y, letter, OSD_TEXT1); + this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); + x=x+w; + i++; + } +} + +static void draw_subtitle(spucmml_decoder_t *this, int64_t sub_start) { + + int line, y; + int font_size; + + this->stream->osd_renderer->filled_rect (this->osd, 0, 0, + this->cached_width-1, this->line_height * SUB_MAX_TEXT - 1, 0); + + y = (SUB_MAX_TEXT - this->lines) * this->line_height; + font_size = this->font_size; + this->stream->osd_renderer->set_encoding(this->osd, this->class->src_encoding); + + for (line=0; linelines; line++) { + int w,x; + while(1) { + w=get_width( this, this->text[line]); + x = (this->cached_width - w) / 2; + + if( w > this->cached_width && font_size > 16 ) { + font_size -= 4; + this->stream->osd_renderer->set_font (this->osd, this->font, font_size); + } else { + break; + } + } + render_line(this, x, y + line*this->line_height, this->text[line]); + } + + if( font_size != this->font_size ) + this->stream->osd_renderer->set_font (this->osd, this->font, this->font_size); + + + this->stream->osd_renderer->set_text_palette (this->osd, -1, OSD_TEXT1); + this->stream->osd_renderer->show (this->osd, sub_start); + + llprintf (LOG_SCHEDULING, + "spucmml: scheduling subtitle >%s< at %"PRId64", current time is %"PRId64"\n", + this->text[0], sub_start, + this->stream->xine->clock->get_current_time (this->stream->xine->clock)); +} + +static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { + + spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; + char *str; + + xml_node_t *packet_xml_root; + char * anchor_text = NULL; + + lprintf("CMML packet seen\n"); + + str = (char *) buf->content; + + /* parse the CMML */ + + xml_parser_init (str, strlen (str), XML_PARSER_CASE_INSENSITIVE); + if (xml_parser_build_tree(&packet_xml_root) != XML_PARSER_OK) { + lprintf ("warning: invalid XML packet detected in CMML track\n"); + return; + } + + if (strcasecmp(packet_xml_root->name, "head") == 0) { + /* found a ... packet: need to parse the title */ + + xml_node_t *title_node; + + /* iterate through children trying to find the title node */ + + for (title_node = packet_xml_root->child; title_node != NULL; title_node = title_node->next) { + + if (strcasecmp (title_node->name, "title") == 0) { + /* found a title node */ + + xine_event_t uevent; + char *title; + int title_len; + + title = title_node->data; + + if (title) + { + xine_ui_data_t data; + /* found a non-empty title */ + lprintf ("found title: \"%s\"\n", title); + + /* set xine meta-info */ + _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, strdup(title)); + + /* and push out a new event signifying the title update on the event + * queue */ + title_len = strlen(title) + 1; + memcpy(data.str, title, title_len); + data.str_len = title_len; + + uevent.type = XINE_EVENT_UI_SET_TITLE; + uevent.stream = this->stream; + uevent.data = &data; + uevent.data_length = sizeof(data); + xine_event_send(this->stream, &uevent); + } + } + } + } else if (strcasecmp(packet_xml_root->name, "clip") == 0) { + /* found a ... packet: search for the in it */ + xml_node_t *clip_node; + + /* iterate through each tag contained in the tag to look for */ + + for (clip_node = packet_xml_root->child; clip_node != NULL; clip_node = clip_node->next) { + + if (strcasecmp (clip_node->name, "a") == 0) { + xml_property_t *href_property; + + /* found the tag: grab its value and its href property */ + + if (clip_node->data) + anchor_text = strdup (clip_node->data); + + for (href_property = clip_node->props; href_property != NULL; href_property = href_property->next) { + if (strcasecmp (href_property->name, "href") == 0) { + /* found the href property */ + char *href = href_property->value; + + if (href) { + lprintf ("found href: \"%s\"\n", href); + this->current_anchor.href = strdup(href); + } + } + } + } + } + } + + /* finish here if we don't have to process any anchor text */ + if (!anchor_text) + return; + + /* how many lines does the anchor text take up? */ + this->lines=0; + { + int i = 0; + while (*anchor_text) { + if (*anchor_text == '\r' || *anchor_text == '\n') { + if (i) { + /* match a newline and there are chars on the current line ... */ + this->text[ this->lines ][i] = '\0'; + this->lines++; + i = 0; + } + } else { + /* found a normal (non-line-ending) character */ + this->text[ this->lines ][i] = *anchor_text; + if (itext[ this->lines ][i] = '\0'; + this->lines++; + } + } + + /* initialize decoder if needed */ + if( !this->cached_width || !this->cached_height || !this->cached_img_duration || !this->osd ) { + if( this->stream->video_out->status(this->stream->video_out, NULL, + &this->cached_width, &this->cached_height, &this->cached_img_duration )) { + if( this->cached_width && this->cached_height && this->cached_img_duration ) { + lprintf("this->stream->osd_renderer is %p\n", this->stream->osd_renderer); + } + } + } + + update_font_size (this); + + if( this->osd ) { + draw_subtitle(this, buf->pts); + return; + } else { + lprintf ("libspucmml: no osd\n"); + } + + return; +} + +static void video_frame_format_change_callback (void *user_data, const xine_event_t *event) +{ + /* this doesn't do anything for now: it's a start at attempting to display + * CMML clips which occur at 0 seconds into the track. see + * + * http://marc.theaimsgroup.com/?l=xine-devel&m=109202443013890&w=2 + * + * for a description of the problem. */ + + switch (event->type) { + case XINE_EVENT_FRAME_FORMAT_CHANGE: + lprintf("video_frame_format_change_callback called!\n"); + break; + default: + lprintf("video_frame_format_change_callback called with unknown event %d\n", event->type); + break; + } +} + +static void spudec_reset (spu_decoder_t *this_gen) { + spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; + + this->cached_width = this->cached_height = 0; +} + +static void spudec_discontinuity (spu_decoder_t *this_gen) { + /* do nothing */ +} + +static void spudec_dispose (spu_decoder_t *this_gen) { + spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; + + if (this->event_queue) + xine_event_dispose_queue (this->event_queue); + + if (this->osd) { + this->stream->osd_renderer->free_object (this->osd); + this->osd = NULL; + } + free(this); +} + +static void update_vertical_offset(void *this_gen, xine_cfg_entry_t *entry) +{ + spucmml_decoder_t *this = (spucmml_decoder_t *)this_gen; + + this->vertical_offset = entry->num_value; + update_font_size(this); +} + +static void update_osd_font(void *this_gen, xine_cfg_entry_t *entry) +{ + spucmml_decoder_t *this = (spucmml_decoder_t *)this_gen; + + this->font = entry->str_value; + + if( this->stream->osd_renderer ) + this->stream->osd_renderer->set_font (this->osd, this->font, this->font_size); +} + +static spu_decoder_t *spucmml_class_open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { + + spucmml_class_t *class = (spucmml_class_t *)class_gen; + spucmml_decoder_t *this ; + + this = (spucmml_decoder_t *) xine_xmalloc (sizeof (spucmml_decoder_t)); + + this->spu_decoder.decode_data = spudec_decode_data; + this->spu_decoder.reset = spudec_reset; + this->spu_decoder.discontinuity = spudec_discontinuity; + this->spu_decoder.dispose = spudec_dispose; + this->spu_decoder.get_interact_info = NULL; + this->spu_decoder.set_button = NULL; + this->spu_decoder.dispose = spudec_dispose; + + this->class = class; + this->stream = stream; + + this->event_queue = xine_event_new_queue (this->stream); + xine_event_create_listener_thread (this->event_queue, + video_frame_format_change_callback, + this); + + this->font_size = 24; + this->subtitle_size = 1; + + this->font = class->xine->config->register_string(class->xine->config, + "subtitles.separate.font", + "sans", + _("font for external subtitles"), + NULL, 0, update_osd_font, this); + + this->vertical_offset = class->xine->config->register_num(class->xine->config, + "subtitles.separate.vertical_offset", + 0, + _("subtitle vertical offset (relative window size)"), + NULL, 0, update_vertical_offset, this); + + this->current_anchor.href = NULL; + + lprintf ("video_out is at %p\n", this->stream->video_out); + + return (spu_decoder_t *) this; +} + +static void spucmml_class_dispose (spu_decoder_class_t *this) { + free (this); +} + +static char *spucmml_class_get_identifier (spu_decoder_class_t *this) { + return "spucmml"; +} + +static char *spucmml_class_get_description (spu_decoder_class_t *this) { + return "CMML subtitle decoder plugin"; +} + +static void update_src_encoding(void *this_gen, xine_cfg_entry_t *entry) +{ + spucmml_class_t *this = (spucmml_class_t *)this_gen; + + this->src_encoding = entry->str_value; + printf("libspucmml: spu_src_encoding = %s\n", this->src_encoding ); +} + +static void *init_spu_decoder_plugin (xine_t *xine, void *data) { + + spucmml_class_t *this ; + + this = (spucmml_class_t *) xine_xmalloc (sizeof (spucmml_class_t)); + + this->class.open_plugin = spucmml_class_open_plugin; + this->class.get_identifier = spucmml_class_get_identifier; + this->class.get_description = spucmml_class_get_description; + this->class.dispose = spucmml_class_dispose; + + this->xine = xine; + + this->src_encoding = xine->config->register_string(xine->config, + "subtitles.separate.src_encoding", + "iso-8859-1", + _("encoding of subtitles"), + NULL, 10, update_src_encoding, this); + + return &this->class; +} + + +/* plugin catalog information */ +static uint32_t supported_types[] = { BUF_SPU_CMML, 0 }; + +static const decoder_info_t spudec_info = { + supported_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_SPU_DECODER, 16, "spucmml", XINE_VERSION_CODE, &spudec_info, &init_spu_decoder_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; + diff --git a/src/libspucmml/xine_decoder.c b/src/libspucmml/xine_decoder.c deleted file mode 100644 index 13cb6c066..000000000 --- a/src/libspucmml/xine_decoder.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.8 2006/07/10 22:08:30 dgp85 Exp $ - * - */ - -#define LOG_MODULE "libspucmml" -#define LOG_VERBOSE -/* -#define LOG -*/ -#define LOG_OSD 0 -#define LOG_SCHEDULING 0 -#define LOG_WIDTH 0 - -#define SUB_BUFSIZE 1024 -#define SUB_MAX_TEXT 5 - -#include "xine_internal.h" - -typedef enum { - SUBTITLE_SIZE_SMALL = 0, - SUBTITLE_SIZE_NORMAL, - SUBTITLE_SIZE_LARGE, - - SUBTITLE_SIZE_NUM /* number of values in enum */ -} subtitle_size; - - -typedef struct spucmml_class_s { - spu_decoder_class_t class; - char *src_encoding; /* encoding of subtitle file */ - xine_t *xine; - -} spucmml_class_t; - - -typedef struct cmml_anchor_s { - char *text; - char *href; -} cmml_anchor_t; - - -typedef struct spucmml_decoder_s { - spu_decoder_t spu_decoder; - - spucmml_class_t *class; - xine_stream_t *stream; - - xine_event_queue_t *event_queue; - - int lines; - char text[SUB_MAX_TEXT][SUB_BUFSIZE]; - - int cached_width; /* frame width */ - int cached_height; /* frame height */ - int64_t cached_img_duration; - int font_size; - int line_height; - int master_started; - int slave_started; - - char *font; /* subtitle font */ - subtitle_size subtitle_size; /* size of subtitles */ - int vertical_offset; - - osd_object_t *osd; - - cmml_anchor_t current_anchor; -} spucmml_decoder_t; - - -static void video_frame_format_change_callback (void *user_data, const xine_event_t *event); - - -static void update_font_size (spucmml_decoder_t *this) { - static int sizes[SUBTITLE_SIZE_NUM][4] = { - { 16, 16, 16, 20 }, /* SUBTITLE_SIZE_SMALL */ - { 16, 16, 20, 24 }, /* SUBTITLE_SIZE_NORMAL */ - { 16, 20, 24, 32 }, /* SUBTITLE_SIZE_LARGE */ - }; - - int *vec = sizes[this->subtitle_size]; - int y; - - if( this->cached_width >= 512 ) - this->font_size = vec[3]; - else if( this->cached_width >= 384 ) - this->font_size = vec[2]; - else if( this->cached_width >= 320 ) - this->font_size = vec[1]; - else - this->font_size = vec[0]; - - this->line_height = this->font_size + 10; - - y = this->cached_height - (SUB_MAX_TEXT * this->line_height) - 5; - - if(((y - this->vertical_offset) >= 0) && ((y - this->vertical_offset) <= this->cached_height)) - y -= this->vertical_offset; - - /* TODO: we should move this stuff below into another function */ - - if (this->osd) - this->stream->osd_renderer->free_object (this->osd); - - llprintf (LOG_OSD, - "pre new_object: osd=%p, osd_renderer=%p, width=%d, height=%d\n", - this->osd, - this->stream->osd_renderer, - this->cached_width, - SUB_MAX_TEXT * this->line_height); - - this->osd = this->stream->osd_renderer->new_object (this->stream->osd_renderer, - this->cached_width, SUB_MAX_TEXT * this->line_height); - - llprintf (LOG_OSD, "post new_object: osd is %p\n", this->osd); - - if(this->stream->osd_renderer) { - this->stream->osd_renderer->set_font (this->osd, this->font, this->font_size); - this->stream->osd_renderer->set_position (this->osd, 0, y); - } -} - -static int get_width(spucmml_decoder_t *this, char* text) { - size_t i=0; - int width=0,w,dummy; - char letter[2]={0, 0}; - - while (i<=strlen(text)) { - switch (text[i]) { - case '<': - if (!strncmp("", text+i, 3)) { - /*Do somethink to enable BOLD typeface*/ - i=i+3; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable BOLD typeface*/ - i=i+4; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to enable italics typeface*/ - i=i+3; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable italics typeface*/ - i=i+4; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable typing - fixme - no teststreams*/ - i=i+6; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to enable typing - fixme - no teststreams*/ - i=i+7; - break; - } - default: - letter[0]=text[i]; - this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); - width=width+w; - i++; - } - } - - llprintf(LOG_WIDTH, "get_width returning width of %d\n", width); - - return width; -} - -static void render_line(spucmml_decoder_t *this, int x, int y, char* text) { - size_t i=0; - int w,dummy; - char letter[2]={0,0}; - - while (i<=strlen(text)) { - letter[0]=text[i]; - this->stream->osd_renderer->render_text(this->osd, x, y, letter, OSD_TEXT1); - this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); - x=x+w; - i++; - } -} - -static void draw_subtitle(spucmml_decoder_t *this, int64_t sub_start) { - - int line, y; - int font_size; - - this->stream->osd_renderer->filled_rect (this->osd, 0, 0, - this->cached_width-1, this->line_height * SUB_MAX_TEXT - 1, 0); - - y = (SUB_MAX_TEXT - this->lines) * this->line_height; - font_size = this->font_size; - this->stream->osd_renderer->set_encoding(this->osd, this->class->src_encoding); - - for (line=0; linelines; line++) { - int w,x; - while(1) { - w=get_width( this, this->text[line]); - x = (this->cached_width - w) / 2; - - if( w > this->cached_width && font_size > 16 ) { - font_size -= 4; - this->stream->osd_renderer->set_font (this->osd, this->font, font_size); - } else { - break; - } - } - render_line(this, x, y + line*this->line_height, this->text[line]); - } - - if( font_size != this->font_size ) - this->stream->osd_renderer->set_font (this->osd, this->font, this->font_size); - - - this->stream->osd_renderer->set_text_palette (this->osd, -1, OSD_TEXT1); - this->stream->osd_renderer->show (this->osd, sub_start); - - llprintf (LOG_SCHEDULING, - "spucmml: scheduling subtitle >%s< at %"PRId64", current time is %"PRId64"\n", - this->text[0], sub_start, - this->stream->xine->clock->get_current_time (this->stream->xine->clock)); -} - -static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { - - spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; - char *str; - - xml_node_t *packet_xml_root; - char * anchor_text = NULL; - - lprintf("CMML packet seen\n"); - - str = (char *) buf->content; - - /* parse the CMML */ - - xml_parser_init (str, strlen (str), XML_PARSER_CASE_INSENSITIVE); - if (xml_parser_build_tree(&packet_xml_root) != XML_PARSER_OK) { - lprintf ("warning: invalid XML packet detected in CMML track\n"); - return; - } - - if (strcasecmp(packet_xml_root->name, "head") == 0) { - /* found a ... packet: need to parse the title */ - - xml_node_t *title_node; - - /* iterate through children trying to find the title node */ - - for (title_node = packet_xml_root->child; title_node != NULL; title_node = title_node->next) { - - if (strcasecmp (title_node->name, "title") == 0) { - /* found a title node */ - - xine_event_t uevent; - char *title; - int title_len; - - title = title_node->data; - - if (title) - { - xine_ui_data_t data; - /* found a non-empty title */ - lprintf ("found title: \"%s\"\n", title); - - /* set xine meta-info */ - _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, strdup(title)); - - /* and push out a new event signifying the title update on the event - * queue */ - title_len = strlen(title) + 1; - memcpy(data.str, title, title_len); - data.str_len = title_len; - - uevent.type = XINE_EVENT_UI_SET_TITLE; - uevent.stream = this->stream; - uevent.data = &data; - uevent.data_length = sizeof(data); - xine_event_send(this->stream, &uevent); - } - } - } - } else if (strcasecmp(packet_xml_root->name, "clip") == 0) { - /* found a ... packet: search for the in it */ - xml_node_t *clip_node; - - /* iterate through each tag contained in the tag to look for */ - - for (clip_node = packet_xml_root->child; clip_node != NULL; clip_node = clip_node->next) { - - if (strcasecmp (clip_node->name, "a") == 0) { - xml_property_t *href_property; - - /* found the tag: grab its value and its href property */ - - if (clip_node->data) - anchor_text = strdup (clip_node->data); - - for (href_property = clip_node->props; href_property != NULL; href_property = href_property->next) { - if (strcasecmp (href_property->name, "href") == 0) { - /* found the href property */ - char *href = href_property->value; - - if (href) { - lprintf ("found href: \"%s\"\n", href); - this->current_anchor.href = strdup(href); - } - } - } - } - } - } - - /* finish here if we don't have to process any anchor text */ - if (!anchor_text) - return; - - /* how many lines does the anchor text take up? */ - this->lines=0; - { - int i = 0; - while (*anchor_text) { - if (*anchor_text == '\r' || *anchor_text == '\n') { - if (i) { - /* match a newline and there are chars on the current line ... */ - this->text[ this->lines ][i] = '\0'; - this->lines++; - i = 0; - } - } else { - /* found a normal (non-line-ending) character */ - this->text[ this->lines ][i] = *anchor_text; - if (itext[ this->lines ][i] = '\0'; - this->lines++; - } - } - - /* initialize decoder if needed */ - if( !this->cached_width || !this->cached_height || !this->cached_img_duration || !this->osd ) { - if( this->stream->video_out->status(this->stream->video_out, NULL, - &this->cached_width, &this->cached_height, &this->cached_img_duration )) { - if( this->cached_width && this->cached_height && this->cached_img_duration ) { - lprintf("this->stream->osd_renderer is %p\n", this->stream->osd_renderer); - } - } - } - - update_font_size (this); - - if( this->osd ) { - draw_subtitle(this, buf->pts); - return; - } else { - lprintf ("libspucmml: no osd\n"); - } - - return; -} - -static void video_frame_format_change_callback (void *user_data, const xine_event_t *event) -{ - /* this doesn't do anything for now: it's a start at attempting to display - * CMML clips which occur at 0 seconds into the track. see - * - * http://marc.theaimsgroup.com/?l=xine-devel&m=109202443013890&w=2 - * - * for a description of the problem. */ - - switch (event->type) { - case XINE_EVENT_FRAME_FORMAT_CHANGE: - lprintf("video_frame_format_change_callback called!\n"); - break; - default: - lprintf("video_frame_format_change_callback called with unknown event %d\n", event->type); - break; - } -} - -static void spudec_reset (spu_decoder_t *this_gen) { - spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; - - this->cached_width = this->cached_height = 0; -} - -static void spudec_discontinuity (spu_decoder_t *this_gen) { - /* do nothing */ -} - -static void spudec_dispose (spu_decoder_t *this_gen) { - spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; - - if (this->event_queue) - xine_event_dispose_queue (this->event_queue); - - if (this->osd) { - this->stream->osd_renderer->free_object (this->osd); - this->osd = NULL; - } - free(this); -} - -static void update_vertical_offset(void *this_gen, xine_cfg_entry_t *entry) -{ - spucmml_decoder_t *this = (spucmml_decoder_t *)this_gen; - - this->vertical_offset = entry->num_value; - update_font_size(this); -} - -static void update_osd_font(void *this_gen, xine_cfg_entry_t *entry) -{ - spucmml_decoder_t *this = (spucmml_decoder_t *)this_gen; - - this->font = entry->str_value; - - if( this->stream->osd_renderer ) - this->stream->osd_renderer->set_font (this->osd, this->font, this->font_size); -} - -static spu_decoder_t *spucmml_class_open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { - - spucmml_class_t *class = (spucmml_class_t *)class_gen; - spucmml_decoder_t *this ; - - this = (spucmml_decoder_t *) xine_xmalloc (sizeof (spucmml_decoder_t)); - - this->spu_decoder.decode_data = spudec_decode_data; - this->spu_decoder.reset = spudec_reset; - this->spu_decoder.discontinuity = spudec_discontinuity; - this->spu_decoder.dispose = spudec_dispose; - this->spu_decoder.get_interact_info = NULL; - this->spu_decoder.set_button = NULL; - this->spu_decoder.dispose = spudec_dispose; - - this->class = class; - this->stream = stream; - - this->event_queue = xine_event_new_queue (this->stream); - xine_event_create_listener_thread (this->event_queue, - video_frame_format_change_callback, - this); - - this->font_size = 24; - this->subtitle_size = 1; - - this->font = class->xine->config->register_string(class->xine->config, - "subtitles.separate.font", - "sans", - _("font for external subtitles"), - NULL, 0, update_osd_font, this); - - this->vertical_offset = class->xine->config->register_num(class->xine->config, - "subtitles.separate.vertical_offset", - 0, - _("subtitle vertical offset (relative window size)"), - NULL, 0, update_vertical_offset, this); - - this->current_anchor.href = NULL; - - lprintf ("video_out is at %p\n", this->stream->video_out); - - return (spu_decoder_t *) this; -} - -static void spucmml_class_dispose (spu_decoder_class_t *this) { - free (this); -} - -static char *spucmml_class_get_identifier (spu_decoder_class_t *this) { - return "spucmml"; -} - -static char *spucmml_class_get_description (spu_decoder_class_t *this) { - return "CMML subtitle decoder plugin"; -} - -static void update_src_encoding(void *this_gen, xine_cfg_entry_t *entry) -{ - spucmml_class_t *this = (spucmml_class_t *)this_gen; - - this->src_encoding = entry->str_value; - printf("libspucmml: spu_src_encoding = %s\n", this->src_encoding ); -} - -static void *init_spu_decoder_plugin (xine_t *xine, void *data) { - - spucmml_class_t *this ; - - this = (spucmml_class_t *) xine_xmalloc (sizeof (spucmml_class_t)); - - this->class.open_plugin = spucmml_class_open_plugin; - this->class.get_identifier = spucmml_class_get_identifier; - this->class.get_description = spucmml_class_get_description; - this->class.dispose = spucmml_class_dispose; - - this->xine = xine; - - this->src_encoding = xine->config->register_string(xine->config, - "subtitles.separate.src_encoding", - "iso-8859-1", - _("encoding of subtitles"), - NULL, 10, update_src_encoding, this); - - return &this->class; -} - - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_SPU_CMML, 0 }; - -static const decoder_info_t spudec_info = { - supported_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_SPU_DECODER, 16, "spucmml", XINE_VERSION_CODE, &spudec_info, &init_spu_decoder_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; - -- cgit v1.2.3 From a32ee1f2295ca674287388d60230b9bf11b2cabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:45:40 +0200 Subject: Rename xine_decoder.c to xine_spu_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libspudec/xine_decoder.c => src/libspudec/xine_spu_decoder.c --- src/libspudec/Makefile.am | 10 +- src/libspudec/xine_decoder.c | 404 --------------------------------------- src/libspudec/xine_spu_decoder.c | 404 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 408 insertions(+), 410 deletions(-) delete mode 100644 src/libspudec/xine_decoder.c create mode 100644 src/libspudec/xine_spu_decoder.c (limited to 'src') diff --git a/src/libspudec/Makefile.am b/src/libspudec/Makefile.am index d50c49ca6..208d994f5 100644 --- a/src/libspudec/Makefile.am +++ b/src/libspudec/Makefile.am @@ -1,14 +1,12 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_spu.la +xineplug_LTLIBRARIES = xineplug_decode_spu.la if HAVE_DVDNAV xineplug_decode_spu_la_SOURCES = \ spu.c \ - xine_decoder.c + xine_spu_decoder.c xineplug_decode_spu_la_LIBADD = $(XINE_LIB) $(DVDNAV_LIBS) $(PTHREAD_LIBS) else @@ -16,13 +14,13 @@ else xineplug_decode_spu_la_SOURCES = \ nav_read.c \ spu.c \ - xine_decoder.c + xine_spu_decoder.c AM_CPPFLAGS = -I$(top_srcdir)/src/input/libdvdnav xineplug_decode_spu_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) endif xineplug_decode_spu_la_CFLAGS = $(DVDNAV_CFLAGS) $(VISIBILITY_FLAG) -xineplug_decode_spu_la_LDFLAGS = -avoid-version -module +xineplug_decode_spu_la_LDFLAGS = $(xineplug_ldflags) noinst_HEADERS = spu.h diff --git a/src/libspudec/xine_decoder.c b/src/libspudec/xine_decoder.c deleted file mode 100644 index 30c7f18c9..000000000 --- a/src/libspudec/xine_decoder.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (C) 2000-2004 the xine project - * - * Copyright (C) James Courtier-Dutton James@superbug.demon.co.uk - July 2001 - * - * 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: xine_decoder.c,v 1.116 2006/07/10 22:08:30 dgp85 Exp $ - * - * stuff needed to turn libspu into a xine decoder plugin - */ - -#include -#include -#include -#include -#include -#include - -#include "xine_internal.h" -#include "buffer.h" -#include "xine-engine/bswap.h" -#include "xineutils.h" -#include "spu.h" -#ifdef HAVE_DVDNAV -# include -# include -#else -# include "nav_read.h" -# include "nav_types.h" -#endif - -/* -#define LOG_DEBUG 1 -#define LOG_BUTTON 1 -*/ - -static clut_t default_clut[] = { - CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x10, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef), - CLUT_Y_CR_CB_INIT(0x51, 0xef, 0x5a), - CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x36, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef), - CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x51, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x10, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef), - CLUT_Y_CR_CB_INIT(0x5c, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x1c, 0x80, 0x80), - CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef) -}; - -static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { - uint32_t stream_id; - spudec_seq_t *cur_seq; - spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - stream_id = buf->type & 0x1f ; - cur_seq = &this->spudec_stream_state[stream_id].ra_seq; - -#ifdef LOG_DEBUG - printf("libspudec:got buffer type = %x\n", buf->type); -#endif - - /* check, if we need to process the next PCI from the list */ - pthread_mutex_lock(&this->nav_pci_lock); - spudec_update_nav(this); - pthread_mutex_unlock(&this->nav_pci_lock); - - if ( (buf->type & 0xffff0000) != BUF_SPU_DVD || - !(buf->decoder_flags & BUF_FLAG_SPECIAL) || - buf->decoder_info[1] != BUF_SPECIAL_SPU_DVD_SUBTYPE ) - return; - - if ( buf->decoder_info[2] == SPU_DVD_SUBTYPE_CLUT ) { -#ifdef LOG_DEBUG - printf("libspudec: SPU CLUT\n"); -#endif - if (buf->content[0]) { /* cheap endianess detection */ - xine_fast_memcpy(this->state.clut, buf->content, sizeof(uint32_t)*16); - } else { - int i; - uint32_t *clut = (uint32_t*) buf->content; - for (i = 0; i < 16; i++) - this->state.clut[i] = bswap_32(clut[i]); - } - this->state.need_clut = 0; - return; - } - - if ( buf->decoder_info[2] == SPU_DVD_SUBTYPE_NAV ) { -#ifdef LOG_DEBUG - printf("libspudec:got nav packet 1\n"); -#endif - spudec_decode_nav(this,buf); - return; - } - - if ( buf->decoder_info[2] == SPU_DVD_SUBTYPE_VOBSUB_PACKAGE ) { - this->state.vobsub = 1; - } - -#ifdef LOG_DEBUG - printf("libspudec:got buffer type = %x\n", buf->type); -#endif - if (buf->decoder_flags & BUF_FLAG_PREVIEW) /* skip preview data */ - return; - - if (buf->pts) { - metronom_t *metronom = this->stream->metronom; - int64_t vpts = metronom->got_spu_packet(metronom, buf->pts); - - this->spudec_stream_state[stream_id].vpts = vpts; /* Show timer */ - this->spudec_stream_state[stream_id].pts = buf->pts; /* Required to match up with NAV packets */ - } - - spudec_reassembly(this->stream->xine, - &this->spudec_stream_state[stream_id].ra_seq, buf->content, buf->size); - if(this->spudec_stream_state[stream_id].ra_seq.complete == 1) { - if(this->spudec_stream_state[stream_id].ra_seq.broken) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libspudec: dropping broken SPU\n"); - this->spudec_stream_state[stream_id].ra_seq.broken = 0; - } else - spudec_process(this,stream_id); - } -} - -static void spudec_reset (spu_decoder_t *this_gen) { - spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); - int i; - - if( this->menu_handle >= 0 ) - ovl_manager->free_handle(ovl_manager, - this->menu_handle); - this->menu_handle = -1; - - for (i=0; i < MAX_STREAMS; i++) { - if( this->spudec_stream_state[i].overlay_handle >= 0 ) - ovl_manager->free_handle(ovl_manager, - this->spudec_stream_state[i].overlay_handle); - this->spudec_stream_state[i].overlay_handle = -1; - this->spudec_stream_state[i].ra_seq.complete = 1; - this->spudec_stream_state[i].ra_seq.broken = 0; - } - - pthread_mutex_lock(&this->nav_pci_lock); - spudec_clear_nav_list(this); - pthread_mutex_unlock(&this->nav_pci_lock); -} - -static void spudec_discontinuity (spu_decoder_t *this_gen) { - spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - - pthread_mutex_lock(&this->nav_pci_lock); - spudec_clear_nav_list(this); - pthread_mutex_unlock(&this->nav_pci_lock); -} - - -static void spudec_dispose (spu_decoder_t *this_gen) { - - spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - int i; - video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); - - if( this->menu_handle >= 0 ) - ovl_manager->free_handle(ovl_manager, - this->menu_handle); - this->menu_handle = -1; - - for (i=0; i < MAX_STREAMS; i++) { - if( this->spudec_stream_state[i].overlay_handle >= 0 ) - ovl_manager->free_handle(ovl_manager, - this->spudec_stream_state[i].overlay_handle); - this->spudec_stream_state[i].overlay_handle = -1; - free (this->spudec_stream_state[i].ra_seq.buf); - } - - spudec_clear_nav_list(this); - pthread_mutex_destroy(&this->nav_pci_lock); - - free (this->event.object.overlay); - free (this); -} - -/* gets the current already correctly processed nav_pci info */ -/* This is not perfectly in sync with the display, but all the same, */ -/* much closer than doing it at the input stage. */ -/* returns a bool for error/success.*/ -static int spudec_get_interact_info (spu_decoder_t *this_gen, void *data) { - spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - /*printf("get_interact_info() called\n");*/ - if (!this || !data) - return 0; - - /*printf("get_interact_info() coping nav_pci\n");*/ - pthread_mutex_lock(&this->nav_pci_lock); - spudec_update_nav(this); - memcpy(data, &this->pci_cur.pci, sizeof(pci_t) ); - pthread_mutex_unlock(&this->nav_pci_lock); - return 1; - -} - -static void spudec_set_button (spu_decoder_t *this_gen, int32_t button, int32_t show) { - spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - /* This function will move to video_overlay - * when video_overlay does menus */ - - video_overlay_manager_t *ovl_manager; - video_overlay_event_t *overlay_event = NULL; - vo_overlay_t *overlay = NULL; - overlay_event = xine_xmalloc (sizeof(video_overlay_event_t)); - - overlay = xine_xmalloc (sizeof(vo_overlay_t)); - /* FIXME: Watch out for threads. We should really put a lock on this - * because events is a different thread than decode_data */ - - if( this->menu_handle < 0 ) { - if (this->stream->video_out) { - ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); - this->menu_handle = ovl_manager->get_handle(ovl_manager,1); - } - } -#ifdef LOG_BUTTON - printf ("libspudec:xine_decoder.c:spudec_event_listener:this=%p\n",this); - printf ("libspudec:xine_decoder.c:spudec_event_listener:this->menu_handle=%d\n",this->menu_handle); -#endif - if(this->menu_handle < 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "Menu handle alloc failed. No more overlays objects available. Only %d at once please.", - MAX_OBJECTS); - free(overlay_event); - free(overlay); - return; - } - - if (show > 0) { -#ifdef LOG_NAV - fprintf (stderr,"libspudec:xine_decoder.c:spudec_event_listener:buttonN = %u show=%d\n", - button, - show); -#endif - this->buttonN = button; - if (this->button_filter != 1) { -#ifdef LOG_BUTTON - fprintf (stdout,"libspudec:xine_decoder.c:spudec_event_listener:buttonN updates not allowed\n"); -#endif - /* Only update highlight is the menu will let us */ - free(overlay_event); - free(overlay); - return; - } - if (show == 2) { - this->button_filter = 2; - } - pthread_mutex_lock(&this->nav_pci_lock); - spudec_update_nav(this); - overlay_event->object.handle = this->menu_handle; - overlay_event->object.pts = this->pci_cur.pci.hli.hl_gi.hli_s_ptm; - overlay_event->object.overlay=overlay; - overlay_event->event_type = OVERLAY_EVENT_MENU_BUTTON; -#ifdef LOG_BUTTON - fprintf(stderr, "libspudec:Button Overlay\n"); -#endif - spudec_copy_nav_to_overlay(this->stream->xine, &this->pci_cur.pci, this->state.clut, - this->buttonN, show-1, overlay, &this->overlay ); - pthread_mutex_unlock(&this->nav_pci_lock); - } else { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "libspudec:xine_decoder.c:spudec_event_listener:HIDE ????\n"); - printf("We dropped out here for some reason"); - _x_abort(); - overlay_event->object.handle = this->menu_handle; - overlay_event->event_type = OVERLAY_EVENT_HIDE; - } - overlay_event->vpts = 0; - if (this->stream->video_out) { - ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); -#ifdef LOG_BUTTON - fprintf(stderr, "libspudec: add_event type=%d : current time=%lld, spu vpts=%lli\n", - overlay_event->event_type, - this->stream->xine->clock->get_current_time(this->stream->xine->clock), - overlay_event->vpts); -#endif - ovl_manager->add_event (ovl_manager, (void *)overlay_event); - free(overlay_event); - free(overlay); - } else { - free(overlay_event); - free(overlay); - } - return; -} - -static spu_decoder_t *open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { - - spudec_decoder_t *this ; - int i; - - this = (spudec_decoder_t *) xine_xmalloc (sizeof (spudec_decoder_t)); - - this->spu_decoder.decode_data = spudec_decode_data; - this->spu_decoder.reset = spudec_reset; - this->spu_decoder.discontinuity = spudec_discontinuity; - this->spu_decoder.dispose = spudec_dispose; - this->spu_decoder.get_interact_info = spudec_get_interact_info; - this->spu_decoder.set_button = spudec_set_button; - this->stream = stream; - this->class = (spudec_class_t *) class_gen; - - this->menu_handle = -1; - this->buttonN = 1; - this->event.object.overlay = xine_xmalloc(sizeof(vo_overlay_t)); - - pthread_mutex_init(&this->nav_pci_lock, NULL); - this->pci_cur.pci.hli.hl_gi.hli_ss = 0; - this->pci_cur.next = NULL; - - this->ovl_caps = stream->video_out->get_capabilities(stream->video_out); - this->output_open = 0; - this->last_event_vpts = 0; - for (i=0; i < MAX_STREAMS; i++) { - this->spudec_stream_state[i].ra_seq.complete = 1; - this->spudec_stream_state[i].overlay_handle = -1; - } - -/* FIXME:Do we really need a default clut? */ - xine_fast_memcpy(this->state.clut, default_clut, sizeof(this->state.clut)); - this->state.need_clut = 1; - this->state.vobsub = 0; - - return &this->spu_decoder; -} - -static char *get_identifier (spu_decoder_class_t *this) { -#ifdef LOG_DEBUG - printf ("libspudec:get_identifier called\n"); -#endif - return "spudec"; -} - -static char *get_description (spu_decoder_class_t *this) { -#ifdef LOG_DEBUG - printf ("libspudec:get_description called\n"); -#endif - return "DVD/VOB SPU decoder plugin"; -} - -static void dispose_class (spu_decoder_class_t *this) { -#ifdef LOG_DEBUG - printf ("libspudec:dispose_class called\n"); -#endif - free (this); -} - - -static void *init_plugin (xine_t *xine, void *data) { - - spudec_class_t *this; - - this = (spudec_class_t *) xine_xmalloc (sizeof (spudec_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - lprintf ("libspudec:init_plugin called\n"); - return this; -} - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_SPU_DVD, 0 }; - -static const decoder_info_t dec_info_data = { - supported_types, /* supported types */ - 5 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_SPU_DECODER, 16, "spudec", XINE_VERSION_CODE, &dec_info_data, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libspudec/xine_spu_decoder.c b/src/libspudec/xine_spu_decoder.c new file mode 100644 index 000000000..30c7f18c9 --- /dev/null +++ b/src/libspudec/xine_spu_decoder.c @@ -0,0 +1,404 @@ +/* + * Copyright (C) 2000-2004 the xine project + * + * Copyright (C) James Courtier-Dutton James@superbug.demon.co.uk - July 2001 + * + * 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: xine_decoder.c,v 1.116 2006/07/10 22:08:30 dgp85 Exp $ + * + * stuff needed to turn libspu into a xine decoder plugin + */ + +#include +#include +#include +#include +#include +#include + +#include "xine_internal.h" +#include "buffer.h" +#include "xine-engine/bswap.h" +#include "xineutils.h" +#include "spu.h" +#ifdef HAVE_DVDNAV +# include +# include +#else +# include "nav_read.h" +# include "nav_types.h" +#endif + +/* +#define LOG_DEBUG 1 +#define LOG_BUTTON 1 +*/ + +static clut_t default_clut[] = { + CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x10, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef), + CLUT_Y_CR_CB_INIT(0x51, 0xef, 0x5a), + CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x36, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef), + CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x51, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x10, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef), + CLUT_Y_CR_CB_INIT(0x5c, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0xbf, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x1c, 0x80, 0x80), + CLUT_Y_CR_CB_INIT(0x28, 0x6d, 0xef) +}; + +static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { + uint32_t stream_id; + spudec_seq_t *cur_seq; + spudec_decoder_t *this = (spudec_decoder_t *) this_gen; + stream_id = buf->type & 0x1f ; + cur_seq = &this->spudec_stream_state[stream_id].ra_seq; + +#ifdef LOG_DEBUG + printf("libspudec:got buffer type = %x\n", buf->type); +#endif + + /* check, if we need to process the next PCI from the list */ + pthread_mutex_lock(&this->nav_pci_lock); + spudec_update_nav(this); + pthread_mutex_unlock(&this->nav_pci_lock); + + if ( (buf->type & 0xffff0000) != BUF_SPU_DVD || + !(buf->decoder_flags & BUF_FLAG_SPECIAL) || + buf->decoder_info[1] != BUF_SPECIAL_SPU_DVD_SUBTYPE ) + return; + + if ( buf->decoder_info[2] == SPU_DVD_SUBTYPE_CLUT ) { +#ifdef LOG_DEBUG + printf("libspudec: SPU CLUT\n"); +#endif + if (buf->content[0]) { /* cheap endianess detection */ + xine_fast_memcpy(this->state.clut, buf->content, sizeof(uint32_t)*16); + } else { + int i; + uint32_t *clut = (uint32_t*) buf->content; + for (i = 0; i < 16; i++) + this->state.clut[i] = bswap_32(clut[i]); + } + this->state.need_clut = 0; + return; + } + + if ( buf->decoder_info[2] == SPU_DVD_SUBTYPE_NAV ) { +#ifdef LOG_DEBUG + printf("libspudec:got nav packet 1\n"); +#endif + spudec_decode_nav(this,buf); + return; + } + + if ( buf->decoder_info[2] == SPU_DVD_SUBTYPE_VOBSUB_PACKAGE ) { + this->state.vobsub = 1; + } + +#ifdef LOG_DEBUG + printf("libspudec:got buffer type = %x\n", buf->type); +#endif + if (buf->decoder_flags & BUF_FLAG_PREVIEW) /* skip preview data */ + return; + + if (buf->pts) { + metronom_t *metronom = this->stream->metronom; + int64_t vpts = metronom->got_spu_packet(metronom, buf->pts); + + this->spudec_stream_state[stream_id].vpts = vpts; /* Show timer */ + this->spudec_stream_state[stream_id].pts = buf->pts; /* Required to match up with NAV packets */ + } + + spudec_reassembly(this->stream->xine, + &this->spudec_stream_state[stream_id].ra_seq, buf->content, buf->size); + if(this->spudec_stream_state[stream_id].ra_seq.complete == 1) { + if(this->spudec_stream_state[stream_id].ra_seq.broken) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libspudec: dropping broken SPU\n"); + this->spudec_stream_state[stream_id].ra_seq.broken = 0; + } else + spudec_process(this,stream_id); + } +} + +static void spudec_reset (spu_decoder_t *this_gen) { + spudec_decoder_t *this = (spudec_decoder_t *) this_gen; + video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); + int i; + + if( this->menu_handle >= 0 ) + ovl_manager->free_handle(ovl_manager, + this->menu_handle); + this->menu_handle = -1; + + for (i=0; i < MAX_STREAMS; i++) { + if( this->spudec_stream_state[i].overlay_handle >= 0 ) + ovl_manager->free_handle(ovl_manager, + this->spudec_stream_state[i].overlay_handle); + this->spudec_stream_state[i].overlay_handle = -1; + this->spudec_stream_state[i].ra_seq.complete = 1; + this->spudec_stream_state[i].ra_seq.broken = 0; + } + + pthread_mutex_lock(&this->nav_pci_lock); + spudec_clear_nav_list(this); + pthread_mutex_unlock(&this->nav_pci_lock); +} + +static void spudec_discontinuity (spu_decoder_t *this_gen) { + spudec_decoder_t *this = (spudec_decoder_t *) this_gen; + + pthread_mutex_lock(&this->nav_pci_lock); + spudec_clear_nav_list(this); + pthread_mutex_unlock(&this->nav_pci_lock); +} + + +static void spudec_dispose (spu_decoder_t *this_gen) { + + spudec_decoder_t *this = (spudec_decoder_t *) this_gen; + int i; + video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); + + if( this->menu_handle >= 0 ) + ovl_manager->free_handle(ovl_manager, + this->menu_handle); + this->menu_handle = -1; + + for (i=0; i < MAX_STREAMS; i++) { + if( this->spudec_stream_state[i].overlay_handle >= 0 ) + ovl_manager->free_handle(ovl_manager, + this->spudec_stream_state[i].overlay_handle); + this->spudec_stream_state[i].overlay_handle = -1; + free (this->spudec_stream_state[i].ra_seq.buf); + } + + spudec_clear_nav_list(this); + pthread_mutex_destroy(&this->nav_pci_lock); + + free (this->event.object.overlay); + free (this); +} + +/* gets the current already correctly processed nav_pci info */ +/* This is not perfectly in sync with the display, but all the same, */ +/* much closer than doing it at the input stage. */ +/* returns a bool for error/success.*/ +static int spudec_get_interact_info (spu_decoder_t *this_gen, void *data) { + spudec_decoder_t *this = (spudec_decoder_t *) this_gen; + /*printf("get_interact_info() called\n");*/ + if (!this || !data) + return 0; + + /*printf("get_interact_info() coping nav_pci\n");*/ + pthread_mutex_lock(&this->nav_pci_lock); + spudec_update_nav(this); + memcpy(data, &this->pci_cur.pci, sizeof(pci_t) ); + pthread_mutex_unlock(&this->nav_pci_lock); + return 1; + +} + +static void spudec_set_button (spu_decoder_t *this_gen, int32_t button, int32_t show) { + spudec_decoder_t *this = (spudec_decoder_t *) this_gen; + /* This function will move to video_overlay + * when video_overlay does menus */ + + video_overlay_manager_t *ovl_manager; + video_overlay_event_t *overlay_event = NULL; + vo_overlay_t *overlay = NULL; + overlay_event = xine_xmalloc (sizeof(video_overlay_event_t)); + + overlay = xine_xmalloc (sizeof(vo_overlay_t)); + /* FIXME: Watch out for threads. We should really put a lock on this + * because events is a different thread than decode_data */ + + if( this->menu_handle < 0 ) { + if (this->stream->video_out) { + ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); + this->menu_handle = ovl_manager->get_handle(ovl_manager,1); + } + } +#ifdef LOG_BUTTON + printf ("libspudec:xine_decoder.c:spudec_event_listener:this=%p\n",this); + printf ("libspudec:xine_decoder.c:spudec_event_listener:this->menu_handle=%d\n",this->menu_handle); +#endif + if(this->menu_handle < 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "Menu handle alloc failed. No more overlays objects available. Only %d at once please.", + MAX_OBJECTS); + free(overlay_event); + free(overlay); + return; + } + + if (show > 0) { +#ifdef LOG_NAV + fprintf (stderr,"libspudec:xine_decoder.c:spudec_event_listener:buttonN = %u show=%d\n", + button, + show); +#endif + this->buttonN = button; + if (this->button_filter != 1) { +#ifdef LOG_BUTTON + fprintf (stdout,"libspudec:xine_decoder.c:spudec_event_listener:buttonN updates not allowed\n"); +#endif + /* Only update highlight is the menu will let us */ + free(overlay_event); + free(overlay); + return; + } + if (show == 2) { + this->button_filter = 2; + } + pthread_mutex_lock(&this->nav_pci_lock); + spudec_update_nav(this); + overlay_event->object.handle = this->menu_handle; + overlay_event->object.pts = this->pci_cur.pci.hli.hl_gi.hli_s_ptm; + overlay_event->object.overlay=overlay; + overlay_event->event_type = OVERLAY_EVENT_MENU_BUTTON; +#ifdef LOG_BUTTON + fprintf(stderr, "libspudec:Button Overlay\n"); +#endif + spudec_copy_nav_to_overlay(this->stream->xine, &this->pci_cur.pci, this->state.clut, + this->buttonN, show-1, overlay, &this->overlay ); + pthread_mutex_unlock(&this->nav_pci_lock); + } else { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "libspudec:xine_decoder.c:spudec_event_listener:HIDE ????\n"); + printf("We dropped out here for some reason"); + _x_abort(); + overlay_event->object.handle = this->menu_handle; + overlay_event->event_type = OVERLAY_EVENT_HIDE; + } + overlay_event->vpts = 0; + if (this->stream->video_out) { + ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); +#ifdef LOG_BUTTON + fprintf(stderr, "libspudec: add_event type=%d : current time=%lld, spu vpts=%lli\n", + overlay_event->event_type, + this->stream->xine->clock->get_current_time(this->stream->xine->clock), + overlay_event->vpts); +#endif + ovl_manager->add_event (ovl_manager, (void *)overlay_event); + free(overlay_event); + free(overlay); + } else { + free(overlay_event); + free(overlay); + } + return; +} + +static spu_decoder_t *open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { + + spudec_decoder_t *this ; + int i; + + this = (spudec_decoder_t *) xine_xmalloc (sizeof (spudec_decoder_t)); + + this->spu_decoder.decode_data = spudec_decode_data; + this->spu_decoder.reset = spudec_reset; + this->spu_decoder.discontinuity = spudec_discontinuity; + this->spu_decoder.dispose = spudec_dispose; + this->spu_decoder.get_interact_info = spudec_get_interact_info; + this->spu_decoder.set_button = spudec_set_button; + this->stream = stream; + this->class = (spudec_class_t *) class_gen; + + this->menu_handle = -1; + this->buttonN = 1; + this->event.object.overlay = xine_xmalloc(sizeof(vo_overlay_t)); + + pthread_mutex_init(&this->nav_pci_lock, NULL); + this->pci_cur.pci.hli.hl_gi.hli_ss = 0; + this->pci_cur.next = NULL; + + this->ovl_caps = stream->video_out->get_capabilities(stream->video_out); + this->output_open = 0; + this->last_event_vpts = 0; + for (i=0; i < MAX_STREAMS; i++) { + this->spudec_stream_state[i].ra_seq.complete = 1; + this->spudec_stream_state[i].overlay_handle = -1; + } + +/* FIXME:Do we really need a default clut? */ + xine_fast_memcpy(this->state.clut, default_clut, sizeof(this->state.clut)); + this->state.need_clut = 1; + this->state.vobsub = 0; + + return &this->spu_decoder; +} + +static char *get_identifier (spu_decoder_class_t *this) { +#ifdef LOG_DEBUG + printf ("libspudec:get_identifier called\n"); +#endif + return "spudec"; +} + +static char *get_description (spu_decoder_class_t *this) { +#ifdef LOG_DEBUG + printf ("libspudec:get_description called\n"); +#endif + return "DVD/VOB SPU decoder plugin"; +} + +static void dispose_class (spu_decoder_class_t *this) { +#ifdef LOG_DEBUG + printf ("libspudec:dispose_class called\n"); +#endif + free (this); +} + + +static void *init_plugin (xine_t *xine, void *data) { + + spudec_class_t *this; + + this = (spudec_class_t *) xine_xmalloc (sizeof (spudec_class_t)); + + this->decoder_class.open_plugin = open_plugin; + this->decoder_class.get_identifier = get_identifier; + this->decoder_class.get_description = get_description; + this->decoder_class.dispose = dispose_class; + + lprintf ("libspudec:init_plugin called\n"); + return this; +} + +/* plugin catalog information */ +static uint32_t supported_types[] = { BUF_SPU_DVD, 0 }; + +static const decoder_info_t dec_info_data = { + supported_types, /* supported types */ + 5 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_SPU_DECODER, 16, "spudec", XINE_VERSION_CODE, &dec_info_data, &init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From 4b96dda7e07c3d31f6298f8f185865fe7818dc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:48:04 +0200 Subject: Rename xine_decoder.c to xine_spudvb_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libspudvb/xine_decoder.c => src/libspudvb/xine_spudvb_decoder.c --- src/libspudvb/Makefile.am | 4 +- src/libspudvb/xine_decoder.c | 877 ------------------------------------ src/libspudvb/xine_spudvb_decoder.c | 877 ++++++++++++++++++++++++++++++++++++ 3 files changed, 879 insertions(+), 879 deletions(-) delete mode 100644 src/libspudvb/xine_decoder.c create mode 100644 src/libspudvb/xine_spudvb_decoder.c (limited to 'src') diff --git a/src/libspudvb/Makefile.am b/src/libspudvb/Makefile.am index 1efc8252f..b4ae9befe 100644 --- a/src/libspudvb/Makefile.am +++ b/src/libspudvb/Makefile.am @@ -4,7 +4,7 @@ libdir = $(XINE_PLUGINDIR) lib_LTLIBRARIES = xineplug_decode_spudvb.la -xineplug_decode_spudvb_la_SOURCES = xine_decoder.c +xineplug_decode_spudvb_la_SOURCES = xine_spudvb_decoder.c xineplug_decode_spudvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) xineplug_decode_spudvb_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_spudvb_la_LDFLAGS = -avoid-version -module +xineplug_decode_spudvb_la_LDFLAGS = $(xineplug_ldflags) diff --git a/src/libspudvb/xine_decoder.c b/src/libspudvb/xine_decoder.c deleted file mode 100644 index f2fcfe182..000000000 --- a/src/libspudvb/xine_decoder.c +++ /dev/null @@ -1,877 +0,0 @@ -/* - * Copyright (C) 2004 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.20 2006/07/10 22:08:30 dgp85 Exp $ - * - * DVB Subtitle decoder (ETS 300 743) - * (c) 2004 Mike Lampard - * based on the application dvbsub by Dave Chapman - * - * TODO: - * - Implement support for teletext based subtitles - */ - -#include "pthread.h" -#include "xine_internal.h" -#include "osd.h" -#define MAX_REGIONS 7 - -/* check every DVBSUB_TIMER_DELAY seconds */ -#define DVBSUB_TIMER_DELAY 1 -/* hide subs after n counts of the delay */ -#define SUB_TIMEOUT 6 - -typedef struct { - int x, y; - unsigned char is_visible; -} visible_region_t; - -typedef struct { - int page_time_out; - int page_version_number; - int page_state; - int page_id; - visible_region_t regions[MAX_REGIONS]; -} page_t; - -typedef struct { - int width, height; - int depth; - int win; - int CLUT_id; - int objects_start; - int objects_end; - unsigned int object_pos[65536]; - unsigned char img[720 * 576]; -} region_t; - -typedef struct { -/* dvbsub stuff */ - int x; - int y; - unsigned int curr_obj; - unsigned int curr_reg[64]; - uint8_t *buf; - int i; - int nibble_flag; - int in_scanline; - page_t page; - region_t regions[MAX_REGIONS]; - clut_t colours[256]; - unsigned char trans[256]; -} dvbsub_func_t; - -typedef struct dvb_spu_class_s { - spu_decoder_class_t class; - xine_t *xine; -} dvb_spu_class_t; - -typedef struct dvb_spu_decoder_s { - spu_decoder_t spu_decoder; - - dvb_spu_class_t *class; - xine_stream_t *stream; - - spu_dvb_descriptor_t *spu_descriptor; - - osd_object_t *osd; - char *bitmap; - - char *pes_pkt; - char *pes_pkt_wrptr; - unsigned int pes_pkt_size; - - uint64_t pts; - uint64_t vpts; - uint64_t end_vpts; - - pthread_mutex_t dvbsub_timer_mutex; - /* This is set to non-zero if the timer thread is wanted to stop. */ - int dvbsub_timer_stop; - pthread_t dvbsub_timer_thread; - unsigned int dvbsub_timer_tcount; - dvbsub_func_t *dvbsub; - int show; -} dvb_spu_decoder_t; - - -void create_region (dvb_spu_decoder_t * this, int region_id, int region_width, int region_height, int region_depth); -void do_plot (dvb_spu_decoder_t * this, int r, int x, int y, unsigned char pixel); -void plot (dvb_spu_decoder_t * this, int r, int run_length, unsigned char pixel); -unsigned char next_nibble (dvb_spu_decoder_t * this); -void set_clut (dvb_spu_decoder_t * this, int CLUT_id, int CLUT_entry_id, int Y_value, int Cr_value, int Cb_value, int T_value); -void decode_4bit_pixel_code_string (dvb_spu_decoder_t * this, int r, int object_id, int ofs, int n); -void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o, int ofs, int n); -void process_page_composition_segment (dvb_spu_decoder_t * this); -void process_region_composition_segment (dvb_spu_decoder_t * this); -void process_CLUT_definition_segment (dvb_spu_decoder_t * this); -void process_object_data_segment (dvb_spu_decoder_t * this); -void draw_subtitles (dvb_spu_decoder_t * this); -static void spudec_dispose (spu_decoder_t * this_gen); - -void create_region (dvb_spu_decoder_t * this, int region_id, int region_width, int region_height, int region_depth) -{ - - dvbsub_func_t *dvbsub = this->dvbsub; - - dvbsub->regions[region_id].win = 1; - dvbsub->regions[region_id].width = region_width; - dvbsub->regions[region_id].height = region_height; - - memset (dvbsub->regions[region_id].img, 15, sizeof (dvbsub->regions[region_id].img)); -} - - -void do_plot (dvb_spu_decoder_t * this, int r, int x, int y, unsigned char pixel) -{ - int i; - dvbsub_func_t *dvbsub = this->dvbsub; - - if ((y >= 0) && (y < dvbsub->regions[r].height)) { - i = (y * dvbsub->regions[r].width) + x; - dvbsub->regions[r].img[i] = pixel; - } -} - -void plot (dvb_spu_decoder_t * this, int r, int run_length, unsigned char pixel) -{ - - dvbsub_func_t *dvbsub = this->dvbsub; - - int x2 = dvbsub->x + run_length; - - while (dvbsub->x < x2) { - do_plot (this, r, dvbsub->x, dvbsub->y, pixel); - dvbsub->x++; - } -} - -unsigned char next_nibble (dvb_spu_decoder_t * this) -{ - unsigned char x; - dvbsub_func_t *dvbsub = this->dvbsub; - - if (dvbsub->nibble_flag == 0) { - x = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - dvbsub->nibble_flag = 1; - } - else { - x = (dvbsub->buf[dvbsub->i++] & 0x0f); - dvbsub->nibble_flag = 0; - } - return (x); -} - -void decode_4bit_pixel_code_string (dvb_spu_decoder_t * this, int r, int object_id, int ofs, int n) -{ - int next_bits, switch_1, switch_2, switch_3, run_length, pixel_code; - - dvbsub_func_t *dvbsub = this->dvbsub; - - int bits; - unsigned int data; - int j; - - if (dvbsub->in_scanline == 0) { - dvbsub->in_scanline = 1; - } - dvbsub->nibble_flag = 0; - j = dvbsub->i + n; - while (dvbsub->i < j) { - - bits = 0; - pixel_code = 0; - next_bits = next_nibble (this); - - if (next_bits != 0) { - pixel_code = next_bits; - plot (this, r, 1, pixel_code); - bits += 4; - } - else { - bits += 4; - data = next_nibble (this); - switch_1 = (data & 0x08) >> 3; - bits++; - if (switch_1 == 0) { - run_length = (data & 0x07); - bits += 3; - if (run_length != 0) { - plot (this, r, run_length + 2, pixel_code); - } - else { - break; - } - } - else { - switch_2 = (data & 0x04) >> 2; - bits++; - if (switch_2 == 0) { - run_length = (data & 0x03); - bits += 2; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 4, pixel_code); - } - else { - switch_3 = (data & 0x03); - bits += 2; - switch (switch_3) { - case 0: - plot (this, r, 1, pixel_code); - break; - case 1: - plot (this, r, 2, pixel_code); - break; - case 2: - run_length = next_nibble (this); - bits += 4; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 9, pixel_code); - break; - case 3: - run_length = next_nibble (this); - run_length = (run_length << 4) | next_nibble (this); - bits += 8; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 25, pixel_code); - } - } - } - } - - } - if (dvbsub->nibble_flag == 1) { - dvbsub->i++; - dvbsub->nibble_flag = 0; - } -} - - -void set_clut(dvb_spu_decoder_t *this,int CLUT_id,int CLUT_entry_id,int Y_value, int Cr_value, int Cb_value, int T_value) { - - dvbsub_func_t *dvbsub = this->dvbsub; - - if ((CLUT_id > 15) || (CLUT_entry_id > 15)) { - return; - } - - dvbsub->colours[(CLUT_entry_id)].y=Y_value; - dvbsub->colours[(CLUT_entry_id)].cr=Cr_value; - dvbsub->colours[(CLUT_entry_id)].cb=Cb_value; - - if (Y_value==0) { - dvbsub->trans[CLUT_entry_id]=T_value; - } else { - dvbsub->trans[CLUT_entry_id]=255; - } - -} - -void process_CLUT_definition_segment(dvb_spu_decoder_t *this) { - int page_id, - segment_length, - CLUT_id, - CLUT_version_number; - - int CLUT_entry_id, - CLUT_flag_8_bit, - CLUT_flag_4_bit, - CLUT_flag_2_bit, - full_range_flag, - Y_value, - Cr_value, - Cb_value, - T_value; - dvbsub_func_t *dvbsub = this->dvbsub; - - int j; - - page_id=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; - segment_length=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; - j=dvbsub->i+segment_length; - - CLUT_id=dvbsub->buf[dvbsub->i++]; - CLUT_version_number=(dvbsub->buf[dvbsub->i]&0xf0)>>4; - dvbsub->i++; - - while (dvbsub->i < j) { - CLUT_entry_id=dvbsub->buf[dvbsub->i++]; - - CLUT_flag_2_bit=(dvbsub->buf[dvbsub->i]&0x80)>>7; - CLUT_flag_4_bit=(dvbsub->buf[dvbsub->i]&0x40)>>6; - CLUT_flag_8_bit=(dvbsub->buf[dvbsub->i]&0x20)>>5; - full_range_flag=dvbsub->buf[dvbsub->i]&1; - dvbsub->i++; - - if (full_range_flag==1) { - Y_value=dvbsub->buf[dvbsub->i++]; - Cr_value=dvbsub->buf[dvbsub->i++]; - Cb_value=dvbsub->buf[dvbsub->i++]; - T_value=dvbsub->buf[dvbsub->i++]; - } else { - Y_value=(dvbsub->buf[dvbsub->i]&0xfc)>>2; - Cr_value=(dvbsub->buf[dvbsub->i]&0x2<<2)|((dvbsub->buf[dvbsub->i+1]&0xc0)>>6); - Cb_value=(dvbsub->buf[dvbsub->i+1]&0x2c)>>2; - T_value=dvbsub->buf[dvbsub->i+1]&2; - dvbsub->i+=2; - } - set_clut(this, CLUT_id,CLUT_entry_id,Y_value,Cr_value,Cb_value,T_value); - } -} - -void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o, int ofs, int n) -{ - int data_type; - int j; - - dvbsub_func_t *dvbsub = this->dvbsub; - - j = dvbsub->i + n; - - dvbsub->x = (dvbsub->regions[r].object_pos[o]) >> 16; - dvbsub->y = ((dvbsub->regions[r].object_pos[o]) & 0xffff) + ofs; - while (dvbsub->i < j) { - data_type = dvbsub->buf[dvbsub->i++]; - - switch (data_type) { - case 0: - dvbsub->i++; - case 0x11: - decode_4bit_pixel_code_string (this, r, o, ofs, n - 1); - break; - case 0xf0: - dvbsub->in_scanline = 0; - dvbsub->x = (dvbsub->regions[r].object_pos[o]) >> 16; - dvbsub->y += 2; - break; - default: - lprintf ("unimplemented data_type %02x in pixel_data_sub_block\n", data_type); - } - } - - dvbsub->i = j; -} - -void process_page_composition_segment (dvb_spu_decoder_t * this) -{ - int segment_length; - int region_id, region_x, region_y; - int j; - int r; - dvbsub_func_t *dvbsub = this->dvbsub; - - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - - j = dvbsub->i + segment_length; - - dvbsub->page.page_time_out = dvbsub->buf[dvbsub->i++]; - - dvbsub->page.page_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - dvbsub->page.page_state = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; - dvbsub->i++; - if ((dvbsub->page.page_state != 2) && (dvbsub->page.page_state != 1)) { - return; - } - else { - } - - for (r = 0; r < MAX_REGIONS; r++) { - dvbsub->page.regions[r].is_visible = 0; - } - while (dvbsub->i < j) { - region_id = dvbsub->buf[dvbsub->i++]; - dvbsub->i++; /* reserved */ - region_x = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - region_y = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - - dvbsub->page.regions[region_id].x = region_x; - dvbsub->page.regions[region_id].y = region_y; - dvbsub->page.regions[region_id].is_visible = 1; - - } - -} - - -void process_region_composition_segment (dvb_spu_decoder_t * this) -{ - int segment_length, - region_id, - region_version_number, - region_fill_flag, region_width, region_height, region_level_of_compatibility, region_depth, CLUT_id, region_8_bit_pixel_code, region_4_bit_pixel_code, region_2_bit_pixel_code; - int object_id, object_type, object_provider_flag, object_x, object_y, foreground_pixel_code, background_pixel_code; - int j; - int o; - dvbsub_func_t *dvbsub = this->dvbsub; - - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - j = dvbsub->i + segment_length; - - region_id = dvbsub->buf[dvbsub->i++]; - region_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - region_fill_flag = (dvbsub->buf[dvbsub->i] & 0x08) >> 3; - dvbsub->i++; - region_width = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - region_height = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - region_level_of_compatibility = (dvbsub->buf[dvbsub->i] & 0xe0) >> 5; - region_depth = (dvbsub->buf[dvbsub->i] & 0x1c) >> 2; - dvbsub->i++; - CLUT_id = dvbsub->buf[dvbsub->i++]; - region_8_bit_pixel_code = dvbsub->buf[dvbsub->i++]; - region_4_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - region_2_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; - dvbsub->i++; - - if(region_id>=MAX_REGIONS) - return; - - if (dvbsub->regions[region_id].win < 0) { - /* If the region doesn't exist, then open it. */ - create_region (this, region_id, region_width, region_height, region_depth); - dvbsub->regions[region_id].CLUT_id = CLUT_id; - } - - dvbsub->regions[region_id].width = region_width; - dvbsub->regions[region_id].height = region_height; - - if (region_fill_flag == 1) { - memset (dvbsub->regions[region_id].img, region_4_bit_pixel_code, sizeof (dvbsub->regions[region_id].img)); - }else{ - memset (this->dvbsub->regions[region_id].img, 15, sizeof (this->dvbsub->regions[region_id].img)); - } - - dvbsub->regions[region_id].objects_start = dvbsub->i; - dvbsub->regions[region_id].objects_end = j; - - for (o = 0; o < 65536; o++) { - dvbsub->regions[region_id].object_pos[o] = 0xffffffff; - } - - while (dvbsub->i < j) { - object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - object_type = (dvbsub->buf[dvbsub->i] & 0xc0) >> 6; - object_provider_flag = (dvbsub->buf[dvbsub->i] & 0x30) >> 4; - object_x = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - object_y = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - - dvbsub->regions[region_id].object_pos[object_id] = (object_x << 16) | object_y; - - if ((object_type == 0x01) || (object_type == 0x02)) { - foreground_pixel_code = dvbsub->buf[dvbsub->i++]; - background_pixel_code = dvbsub->buf[dvbsub->i++]; - } - } - -} - -void process_object_data_segment (dvb_spu_decoder_t * this) -{ - int segment_length, object_id, object_version_number, object_coding_method, non_modifying_colour_flag; - - int top_field_data_block_length, bottom_field_data_block_length; - - dvbsub_func_t *dvbsub = this->dvbsub; - - int j; - int old_i; - int r; - - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - j = dvbsub->i + segment_length; - - object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - dvbsub->curr_obj = object_id; - object_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - object_coding_method = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; - non_modifying_colour_flag = (dvbsub->buf[dvbsub->i] & 0x02) >> 1; - dvbsub->i++; - - old_i = dvbsub->i; - for (r = 0; r < MAX_REGIONS; r++) { - - /* If this object is in this region... */ - if (dvbsub->regions[r].win >= 0) { - if (dvbsub->regions[r].object_pos[object_id] != 0xffffffff) { - dvbsub->i = old_i; - if (object_coding_method == 0) { - top_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - bottom_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - - process_pixel_data_sub_block (this, r, object_id, 0, top_field_data_block_length); - - process_pixel_data_sub_block (this, r, object_id, 1, bottom_field_data_block_length); - } - } - } - } -} - - -/* Sleep routine for pthread */ -static void dvbsub_pthread_sleep(int seconds) { - pthread_mutex_t dummy_mutex; - pthread_cond_t dummy_cond; - struct timespec timeout; - - /* Create a dummy mutex which doesn't unlock for sure while waiting. */ - pthread_mutex_init(&dummy_mutex, NULL); - pthread_mutex_lock(&dummy_mutex); - - /* Create a dummy condition variable. */ - pthread_cond_init(&dummy_cond, NULL); - - timeout.tv_sec = time(NULL) + seconds; - timeout.tv_nsec = 0; - - pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &timeout); - - pthread_cond_destroy(&dummy_cond); - pthread_mutex_unlock(&dummy_mutex); - pthread_mutex_destroy(&dummy_mutex); -} - - -/* Thread routine that checks for subtitle timeout periodically. */ -static void* dvbsub_timer_func(void *this_gen) { - dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - - while (!this->dvbsub_timer_stop) { - pthread_mutex_lock(&this->dvbsub_timer_mutex); - if(this->dvbsub_timer_tcount++ > SUB_TIMEOUT) - this->stream->osd_renderer->hide (this->osd, 0); - pthread_mutex_unlock(&this->dvbsub_timer_mutex); - dvbsub_pthread_sleep(DVBSUB_TIMER_DELAY); - } - return NULL; -} - -void draw_subtitles (dvb_spu_decoder_t * this) -{ - int r; - int x, y, out_y; - int display=0; - /* clear it */ - memset (this->bitmap, 0, 720 * 576); - /* render all regions onto the page */ - /* FIXME: we ought to have an osd per region, to allow for multiple CLUTs */ - out_y = 0; - for (r = 0; r < MAX_REGIONS; r++) { - if (this->dvbsub->regions[r].win >= 0) { - if (this->dvbsub->page.regions[r].is_visible) { - - out_y = this->dvbsub->page.regions[r].y * 720; - for (y = 0; y < this->dvbsub->regions[r].height; y++) { - for (x = 0; x < this->dvbsub->regions[r].width; x++) { - this->bitmap[out_y + x + this->dvbsub->page.regions[r].x] = this->dvbsub->regions[r].img[(y * this->dvbsub->regions[r].width) + x]; - if (this->bitmap[out_y + x + this->dvbsub->page.regions[r].x]) - { - display=1; - } - } - out_y += 720; - } - } - } - } - - if(display){ - - /* start timer thread if stopped */ - if(this->dvbsub_timer_stop){ - this->dvbsub_timer_stop=0; - if (pthread_create(&this->dvbsub_timer_thread, NULL, dvbsub_timer_func, this) != 0) { - xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, _("dvbsub: cannot create timer thread\n")); - } - } - - /* display immediately at requested PTS*/ - this->stream->osd_renderer->set_palette(this->osd,(uint32_t *)this->dvbsub->colours,this->dvbsub->trans); - this->stream->osd_renderer->draw_bitmap (this->osd,this->bitmap, 1,1,720,576,NULL); - - pthread_mutex_lock(&this->dvbsub_timer_mutex); - this->stream->osd_renderer->show (this->osd, this->vpts); - /* reset the timer thread */ - this->dvbsub_timer_tcount=0; - pthread_mutex_unlock(&this->dvbsub_timer_mutex); - } -} - - -static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) -{ - dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - int new_i; - int data_identifier, subtitle_stream_id; - int segment_length, segment_type; - int PES_header_data_length; - int PES_packet_length; - int r; - - if((buf->type & 0xffff0000)!=BUF_SPU_DVB) - return; - - if (buf->decoder_flags & BUF_FLAG_SPECIAL) { - if (buf->decoder_info[1] == BUF_SPECIAL_SPU_DVB_DESCRIPTOR) { - if (buf->decoder_info[2] == 0) { - this->dvbsub_timer_stop=1; - this->stream->osd_renderer->hide (this->osd, 0); - } - else { - xine_fast_memcpy (this->spu_descriptor, buf->decoder_info_ptr[2], buf->decoder_info[2]); - } - } - return; - } - else { - if (buf->decoder_info[2]) { - memset (this->pes_pkt, 0xff, 64*1024); - this->pes_pkt_wrptr = this->pes_pkt; - this->pes_pkt_size = buf->decoder_info[2]; - this->pts = buf->pts; - - xine_fast_memcpy (this->pes_pkt, buf->content, buf->size); - this->pes_pkt_wrptr += buf->size; - } - else { - if (this->pes_pkt && (this->pes_pkt_wrptr != this->pes_pkt)) { - xine_fast_memcpy (this->pes_pkt_wrptr, buf->content, buf->size); - this->pes_pkt_wrptr += buf->size; - } - } - } - /* inform metronom we've received the package */ - if (buf->pts) { - metronom_t *metronom = this->stream->metronom; - this->vpts = metronom->got_spu_packet (metronom, buf->pts); - } - - /* process the pes section */ - - PES_packet_length = this->pes_pkt_size; - - this->dvbsub->buf = this->pes_pkt; - - PES_header_data_length = 0; - this->dvbsub->i = 0; - - data_identifier = this->dvbsub->buf[this->dvbsub->i++]; - subtitle_stream_id = this->dvbsub->buf[this->dvbsub->i++]; - - while (this->dvbsub->i <= (PES_packet_length)) { - /* SUBTITLING SEGMENT */ - this->dvbsub->i++; - segment_type = this->dvbsub->buf[this->dvbsub->i++]; - - this->dvbsub->page.page_id = (this->dvbsub->buf[this->dvbsub->i] << 8) | this->dvbsub->buf[this->dvbsub->i + 1]; - segment_length = (this->dvbsub->buf[this->dvbsub->i + 2] << 8) | this->dvbsub->buf[this->dvbsub->i + 3]; - new_i = this->dvbsub->i + segment_length + 4; - - /* only process complete segments */ - if(new_i > (this->pes_pkt_wrptr - this->pes_pkt)) - break; - /* verify we've the right segment */ - if(this->dvbsub->page.page_id==this->spu_descriptor->comp_page_id){ - /* SEGMENT_DATA_FIELD */ - switch (segment_type & 0xff) { - case 0x10: - process_page_composition_segment (this); - break; - case 0x11: - process_region_composition_segment (this); - break; - case 0x12: - process_CLUT_definition_segment(this); - break; - case 0x13: - process_object_data_segment (this); - break; - case 0x80: /* Page is now completely rendered */ - for (r=0;rdvbsub->regions[r].img, 15, sizeof (this->dvbsub->regions[r].img)); - this->dvbsub->page.regions[r].is_visible=0; - this->dvbsub->regions[r].win = -1; - } - break; - default: - return; - break; - } - draw_subtitles(this); - } - this->dvbsub->i = new_i; - } - - return; -} - -static void spudec_reset (spu_decoder_t * this_gen) -{ - dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - - if (this->osd) - this->stream->osd_renderer->hide (this->osd, 0); - -} - -static void spudec_discontinuity (spu_decoder_t * this_gen) -{ - /* do nothing */ -} - -static void spudec_dispose (spu_decoder_t * this_gen) -{ - dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - - if(!this->dvbsub_timer_stop){ - this->dvbsub_timer_stop=1; - } - - if(this->spu_descriptor){ - free(this->spu_descriptor); - this->spu_descriptor=NULL; - } - - if (this->osd) { - this->stream->osd_renderer->free_object (this->osd); - this->osd = NULL; - } - - if (this->pes_pkt) - free (this->pes_pkt); - - if (this->bitmap) - free (this->bitmap); - - if (this->dvbsub) - free (this->dvbsub); - - free (this); -} - -static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen, xine_stream_t * stream) -{ - - int i; - dvb_spu_decoder_t *this; - dvb_spu_class_t *class = (dvb_spu_class_t *) class_gen; - - this = (dvb_spu_decoder_t *) xine_xmalloc (sizeof (dvb_spu_decoder_t)); - - this->spu_decoder.decode_data = spudec_decode_data; - this->spu_decoder.reset = spudec_reset; - this->spu_decoder.discontinuity = spudec_discontinuity; - this->spu_decoder.dispose = spudec_dispose; - this->spu_decoder.get_interact_info = NULL; - this->spu_decoder.set_button = NULL; - - this->class = class; - this->stream = stream; - - this->pes_pkt = xine_xmalloc (1024*65); - this->bitmap = xine_xmalloc (720*576); - this->spu_descriptor = xine_xmalloc(sizeof(spu_dvb_descriptor_t)); - - this->dvbsub = xine_xmalloc (sizeof (dvbsub_func_t)); - - for (i = 0; i < MAX_REGIONS; i++) { - this->dvbsub->page.regions[i].is_visible = 0; - this->dvbsub->regions[i].win = -1; - } - - this->osd = this->stream->osd_renderer->new_object (this->stream->osd_renderer, 720, 600); - this->stream->osd_renderer->set_position (this->osd, 1, 1); - this->stream->osd_renderer->set_font (this->osd, "cetus", 26); - this->stream->osd_renderer->set_encoding (this->osd, NULL); - this->stream->osd_renderer->set_text_palette (this->osd, TEXTPALETTE_YELLOW_BLACK_TRANSPARENT, OSD_TEXT1); - - - /* subtitle timer thread. */ - this->dvbsub_timer_stop = 1; - - return (spu_decoder_t *) this; -} - -static void dvb_spu_class_dispose (spu_decoder_class_t * this) -{ - free (this); -} - -static char *dvb_spu_class_get_identifier (spu_decoder_class_t * this) -{ - return "spudvb"; -} - -static char *dvb_spu_class_get_description (spu_decoder_class_t * this) -{ - return "DVB subtitle decoder plugin"; -} - -static void *init_spu_decoder_plugin (xine_t * xine, void *data) -{ - - dvb_spu_class_t *this; - this = (dvb_spu_class_t *) xine_xmalloc (sizeof (dvb_spu_class_t)); - - this->class.open_plugin = dvb_spu_class_open_plugin; - this->class.get_identifier = dvb_spu_class_get_identifier; - this->class.get_description = dvb_spu_class_get_description; - this->class.dispose = dvb_spu_class_dispose; - - this->xine = xine; - - return &this->class; -} - - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_SPU_DVB, 0 }; - -static const decoder_info_t spudec_info = { - supported_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { -/* type, API, "name", version, special_info, init_function */ - {PLUGIN_SPU_DECODER, 16, "spudvb", XINE_VERSION_CODE, &spudec_info, - &init_spu_decoder_plugin}, - {PLUGIN_NONE, 0, "", 0, NULL, NULL} -}; diff --git a/src/libspudvb/xine_spudvb_decoder.c b/src/libspudvb/xine_spudvb_decoder.c new file mode 100644 index 000000000..f2fcfe182 --- /dev/null +++ b/src/libspudvb/xine_spudvb_decoder.c @@ -0,0 +1,877 @@ +/* + * Copyright (C) 2004 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.20 2006/07/10 22:08:30 dgp85 Exp $ + * + * DVB Subtitle decoder (ETS 300 743) + * (c) 2004 Mike Lampard + * based on the application dvbsub by Dave Chapman + * + * TODO: + * - Implement support for teletext based subtitles + */ + +#include "pthread.h" +#include "xine_internal.h" +#include "osd.h" +#define MAX_REGIONS 7 + +/* check every DVBSUB_TIMER_DELAY seconds */ +#define DVBSUB_TIMER_DELAY 1 +/* hide subs after n counts of the delay */ +#define SUB_TIMEOUT 6 + +typedef struct { + int x, y; + unsigned char is_visible; +} visible_region_t; + +typedef struct { + int page_time_out; + int page_version_number; + int page_state; + int page_id; + visible_region_t regions[MAX_REGIONS]; +} page_t; + +typedef struct { + int width, height; + int depth; + int win; + int CLUT_id; + int objects_start; + int objects_end; + unsigned int object_pos[65536]; + unsigned char img[720 * 576]; +} region_t; + +typedef struct { +/* dvbsub stuff */ + int x; + int y; + unsigned int curr_obj; + unsigned int curr_reg[64]; + uint8_t *buf; + int i; + int nibble_flag; + int in_scanline; + page_t page; + region_t regions[MAX_REGIONS]; + clut_t colours[256]; + unsigned char trans[256]; +} dvbsub_func_t; + +typedef struct dvb_spu_class_s { + spu_decoder_class_t class; + xine_t *xine; +} dvb_spu_class_t; + +typedef struct dvb_spu_decoder_s { + spu_decoder_t spu_decoder; + + dvb_spu_class_t *class; + xine_stream_t *stream; + + spu_dvb_descriptor_t *spu_descriptor; + + osd_object_t *osd; + char *bitmap; + + char *pes_pkt; + char *pes_pkt_wrptr; + unsigned int pes_pkt_size; + + uint64_t pts; + uint64_t vpts; + uint64_t end_vpts; + + pthread_mutex_t dvbsub_timer_mutex; + /* This is set to non-zero if the timer thread is wanted to stop. */ + int dvbsub_timer_stop; + pthread_t dvbsub_timer_thread; + unsigned int dvbsub_timer_tcount; + dvbsub_func_t *dvbsub; + int show; +} dvb_spu_decoder_t; + + +void create_region (dvb_spu_decoder_t * this, int region_id, int region_width, int region_height, int region_depth); +void do_plot (dvb_spu_decoder_t * this, int r, int x, int y, unsigned char pixel); +void plot (dvb_spu_decoder_t * this, int r, int run_length, unsigned char pixel); +unsigned char next_nibble (dvb_spu_decoder_t * this); +void set_clut (dvb_spu_decoder_t * this, int CLUT_id, int CLUT_entry_id, int Y_value, int Cr_value, int Cb_value, int T_value); +void decode_4bit_pixel_code_string (dvb_spu_decoder_t * this, int r, int object_id, int ofs, int n); +void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o, int ofs, int n); +void process_page_composition_segment (dvb_spu_decoder_t * this); +void process_region_composition_segment (dvb_spu_decoder_t * this); +void process_CLUT_definition_segment (dvb_spu_decoder_t * this); +void process_object_data_segment (dvb_spu_decoder_t * this); +void draw_subtitles (dvb_spu_decoder_t * this); +static void spudec_dispose (spu_decoder_t * this_gen); + +void create_region (dvb_spu_decoder_t * this, int region_id, int region_width, int region_height, int region_depth) +{ + + dvbsub_func_t *dvbsub = this->dvbsub; + + dvbsub->regions[region_id].win = 1; + dvbsub->regions[region_id].width = region_width; + dvbsub->regions[region_id].height = region_height; + + memset (dvbsub->regions[region_id].img, 15, sizeof (dvbsub->regions[region_id].img)); +} + + +void do_plot (dvb_spu_decoder_t * this, int r, int x, int y, unsigned char pixel) +{ + int i; + dvbsub_func_t *dvbsub = this->dvbsub; + + if ((y >= 0) && (y < dvbsub->regions[r].height)) { + i = (y * dvbsub->regions[r].width) + x; + dvbsub->regions[r].img[i] = pixel; + } +} + +void plot (dvb_spu_decoder_t * this, int r, int run_length, unsigned char pixel) +{ + + dvbsub_func_t *dvbsub = this->dvbsub; + + int x2 = dvbsub->x + run_length; + + while (dvbsub->x < x2) { + do_plot (this, r, dvbsub->x, dvbsub->y, pixel); + dvbsub->x++; + } +} + +unsigned char next_nibble (dvb_spu_decoder_t * this) +{ + unsigned char x; + dvbsub_func_t *dvbsub = this->dvbsub; + + if (dvbsub->nibble_flag == 0) { + x = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + dvbsub->nibble_flag = 1; + } + else { + x = (dvbsub->buf[dvbsub->i++] & 0x0f); + dvbsub->nibble_flag = 0; + } + return (x); +} + +void decode_4bit_pixel_code_string (dvb_spu_decoder_t * this, int r, int object_id, int ofs, int n) +{ + int next_bits, switch_1, switch_2, switch_3, run_length, pixel_code; + + dvbsub_func_t *dvbsub = this->dvbsub; + + int bits; + unsigned int data; + int j; + + if (dvbsub->in_scanline == 0) { + dvbsub->in_scanline = 1; + } + dvbsub->nibble_flag = 0; + j = dvbsub->i + n; + while (dvbsub->i < j) { + + bits = 0; + pixel_code = 0; + next_bits = next_nibble (this); + + if (next_bits != 0) { + pixel_code = next_bits; + plot (this, r, 1, pixel_code); + bits += 4; + } + else { + bits += 4; + data = next_nibble (this); + switch_1 = (data & 0x08) >> 3; + bits++; + if (switch_1 == 0) { + run_length = (data & 0x07); + bits += 3; + if (run_length != 0) { + plot (this, r, run_length + 2, pixel_code); + } + else { + break; + } + } + else { + switch_2 = (data & 0x04) >> 2; + bits++; + if (switch_2 == 0) { + run_length = (data & 0x03); + bits += 2; + pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 4, pixel_code); + } + else { + switch_3 = (data & 0x03); + bits += 2; + switch (switch_3) { + case 0: + plot (this, r, 1, pixel_code); + break; + case 1: + plot (this, r, 2, pixel_code); + break; + case 2: + run_length = next_nibble (this); + bits += 4; + pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 9, pixel_code); + break; + case 3: + run_length = next_nibble (this); + run_length = (run_length << 4) | next_nibble (this); + bits += 8; + pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 25, pixel_code); + } + } + } + } + + } + if (dvbsub->nibble_flag == 1) { + dvbsub->i++; + dvbsub->nibble_flag = 0; + } +} + + +void set_clut(dvb_spu_decoder_t *this,int CLUT_id,int CLUT_entry_id,int Y_value, int Cr_value, int Cb_value, int T_value) { + + dvbsub_func_t *dvbsub = this->dvbsub; + + if ((CLUT_id > 15) || (CLUT_entry_id > 15)) { + return; + } + + dvbsub->colours[(CLUT_entry_id)].y=Y_value; + dvbsub->colours[(CLUT_entry_id)].cr=Cr_value; + dvbsub->colours[(CLUT_entry_id)].cb=Cb_value; + + if (Y_value==0) { + dvbsub->trans[CLUT_entry_id]=T_value; + } else { + dvbsub->trans[CLUT_entry_id]=255; + } + +} + +void process_CLUT_definition_segment(dvb_spu_decoder_t *this) { + int page_id, + segment_length, + CLUT_id, + CLUT_version_number; + + int CLUT_entry_id, + CLUT_flag_8_bit, + CLUT_flag_4_bit, + CLUT_flag_2_bit, + full_range_flag, + Y_value, + Cr_value, + Cb_value, + T_value; + dvbsub_func_t *dvbsub = this->dvbsub; + + int j; + + page_id=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; + segment_length=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; + j=dvbsub->i+segment_length; + + CLUT_id=dvbsub->buf[dvbsub->i++]; + CLUT_version_number=(dvbsub->buf[dvbsub->i]&0xf0)>>4; + dvbsub->i++; + + while (dvbsub->i < j) { + CLUT_entry_id=dvbsub->buf[dvbsub->i++]; + + CLUT_flag_2_bit=(dvbsub->buf[dvbsub->i]&0x80)>>7; + CLUT_flag_4_bit=(dvbsub->buf[dvbsub->i]&0x40)>>6; + CLUT_flag_8_bit=(dvbsub->buf[dvbsub->i]&0x20)>>5; + full_range_flag=dvbsub->buf[dvbsub->i]&1; + dvbsub->i++; + + if (full_range_flag==1) { + Y_value=dvbsub->buf[dvbsub->i++]; + Cr_value=dvbsub->buf[dvbsub->i++]; + Cb_value=dvbsub->buf[dvbsub->i++]; + T_value=dvbsub->buf[dvbsub->i++]; + } else { + Y_value=(dvbsub->buf[dvbsub->i]&0xfc)>>2; + Cr_value=(dvbsub->buf[dvbsub->i]&0x2<<2)|((dvbsub->buf[dvbsub->i+1]&0xc0)>>6); + Cb_value=(dvbsub->buf[dvbsub->i+1]&0x2c)>>2; + T_value=dvbsub->buf[dvbsub->i+1]&2; + dvbsub->i+=2; + } + set_clut(this, CLUT_id,CLUT_entry_id,Y_value,Cr_value,Cb_value,T_value); + } +} + +void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o, int ofs, int n) +{ + int data_type; + int j; + + dvbsub_func_t *dvbsub = this->dvbsub; + + j = dvbsub->i + n; + + dvbsub->x = (dvbsub->regions[r].object_pos[o]) >> 16; + dvbsub->y = ((dvbsub->regions[r].object_pos[o]) & 0xffff) + ofs; + while (dvbsub->i < j) { + data_type = dvbsub->buf[dvbsub->i++]; + + switch (data_type) { + case 0: + dvbsub->i++; + case 0x11: + decode_4bit_pixel_code_string (this, r, o, ofs, n - 1); + break; + case 0xf0: + dvbsub->in_scanline = 0; + dvbsub->x = (dvbsub->regions[r].object_pos[o]) >> 16; + dvbsub->y += 2; + break; + default: + lprintf ("unimplemented data_type %02x in pixel_data_sub_block\n", data_type); + } + } + + dvbsub->i = j; +} + +void process_page_composition_segment (dvb_spu_decoder_t * this) +{ + int segment_length; + int region_id, region_x, region_y; + int j; + int r; + dvbsub_func_t *dvbsub = this->dvbsub; + + dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + + j = dvbsub->i + segment_length; + + dvbsub->page.page_time_out = dvbsub->buf[dvbsub->i++]; + + dvbsub->page.page_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + dvbsub->page.page_state = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + dvbsub->i++; + if ((dvbsub->page.page_state != 2) && (dvbsub->page.page_state != 1)) { + return; + } + else { + } + + for (r = 0; r < MAX_REGIONS; r++) { + dvbsub->page.regions[r].is_visible = 0; + } + while (dvbsub->i < j) { + region_id = dvbsub->buf[dvbsub->i++]; + dvbsub->i++; /* reserved */ + region_x = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + region_y = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + + dvbsub->page.regions[region_id].x = region_x; + dvbsub->page.regions[region_id].y = region_y; + dvbsub->page.regions[region_id].is_visible = 1; + + } + +} + + +void process_region_composition_segment (dvb_spu_decoder_t * this) +{ + int segment_length, + region_id, + region_version_number, + region_fill_flag, region_width, region_height, region_level_of_compatibility, region_depth, CLUT_id, region_8_bit_pixel_code, region_4_bit_pixel_code, region_2_bit_pixel_code; + int object_id, object_type, object_provider_flag, object_x, object_y, foreground_pixel_code, background_pixel_code; + int j; + int o; + dvbsub_func_t *dvbsub = this->dvbsub; + + dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + j = dvbsub->i + segment_length; + + region_id = dvbsub->buf[dvbsub->i++]; + region_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + region_fill_flag = (dvbsub->buf[dvbsub->i] & 0x08) >> 3; + dvbsub->i++; + region_width = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + region_height = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + region_level_of_compatibility = (dvbsub->buf[dvbsub->i] & 0xe0) >> 5; + region_depth = (dvbsub->buf[dvbsub->i] & 0x1c) >> 2; + dvbsub->i++; + CLUT_id = dvbsub->buf[dvbsub->i++]; + region_8_bit_pixel_code = dvbsub->buf[dvbsub->i++]; + region_4_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + region_2_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + dvbsub->i++; + + if(region_id>=MAX_REGIONS) + return; + + if (dvbsub->regions[region_id].win < 0) { + /* If the region doesn't exist, then open it. */ + create_region (this, region_id, region_width, region_height, region_depth); + dvbsub->regions[region_id].CLUT_id = CLUT_id; + } + + dvbsub->regions[region_id].width = region_width; + dvbsub->regions[region_id].height = region_height; + + if (region_fill_flag == 1) { + memset (dvbsub->regions[region_id].img, region_4_bit_pixel_code, sizeof (dvbsub->regions[region_id].img)); + }else{ + memset (this->dvbsub->regions[region_id].img, 15, sizeof (this->dvbsub->regions[region_id].img)); + } + + dvbsub->regions[region_id].objects_start = dvbsub->i; + dvbsub->regions[region_id].objects_end = j; + + for (o = 0; o < 65536; o++) { + dvbsub->regions[region_id].object_pos[o] = 0xffffffff; + } + + while (dvbsub->i < j) { + object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + object_type = (dvbsub->buf[dvbsub->i] & 0xc0) >> 6; + object_provider_flag = (dvbsub->buf[dvbsub->i] & 0x30) >> 4; + object_x = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + object_y = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + + dvbsub->regions[region_id].object_pos[object_id] = (object_x << 16) | object_y; + + if ((object_type == 0x01) || (object_type == 0x02)) { + foreground_pixel_code = dvbsub->buf[dvbsub->i++]; + background_pixel_code = dvbsub->buf[dvbsub->i++]; + } + } + +} + +void process_object_data_segment (dvb_spu_decoder_t * this) +{ + int segment_length, object_id, object_version_number, object_coding_method, non_modifying_colour_flag; + + int top_field_data_block_length, bottom_field_data_block_length; + + dvbsub_func_t *dvbsub = this->dvbsub; + + int j; + int old_i; + int r; + + dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + j = dvbsub->i + segment_length; + + object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + dvbsub->curr_obj = object_id; + object_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + object_coding_method = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + non_modifying_colour_flag = (dvbsub->buf[dvbsub->i] & 0x02) >> 1; + dvbsub->i++; + + old_i = dvbsub->i; + for (r = 0; r < MAX_REGIONS; r++) { + + /* If this object is in this region... */ + if (dvbsub->regions[r].win >= 0) { + if (dvbsub->regions[r].object_pos[object_id] != 0xffffffff) { + dvbsub->i = old_i; + if (object_coding_method == 0) { + top_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + bottom_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->i += 2; + + process_pixel_data_sub_block (this, r, object_id, 0, top_field_data_block_length); + + process_pixel_data_sub_block (this, r, object_id, 1, bottom_field_data_block_length); + } + } + } + } +} + + +/* Sleep routine for pthread */ +static void dvbsub_pthread_sleep(int seconds) { + pthread_mutex_t dummy_mutex; + pthread_cond_t dummy_cond; + struct timespec timeout; + + /* Create a dummy mutex which doesn't unlock for sure while waiting. */ + pthread_mutex_init(&dummy_mutex, NULL); + pthread_mutex_lock(&dummy_mutex); + + /* Create a dummy condition variable. */ + pthread_cond_init(&dummy_cond, NULL); + + timeout.tv_sec = time(NULL) + seconds; + timeout.tv_nsec = 0; + + pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &timeout); + + pthread_cond_destroy(&dummy_cond); + pthread_mutex_unlock(&dummy_mutex); + pthread_mutex_destroy(&dummy_mutex); +} + + +/* Thread routine that checks for subtitle timeout periodically. */ +static void* dvbsub_timer_func(void *this_gen) { + dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; + + while (!this->dvbsub_timer_stop) { + pthread_mutex_lock(&this->dvbsub_timer_mutex); + if(this->dvbsub_timer_tcount++ > SUB_TIMEOUT) + this->stream->osd_renderer->hide (this->osd, 0); + pthread_mutex_unlock(&this->dvbsub_timer_mutex); + dvbsub_pthread_sleep(DVBSUB_TIMER_DELAY); + } + return NULL; +} + +void draw_subtitles (dvb_spu_decoder_t * this) +{ + int r; + int x, y, out_y; + int display=0; + /* clear it */ + memset (this->bitmap, 0, 720 * 576); + /* render all regions onto the page */ + /* FIXME: we ought to have an osd per region, to allow for multiple CLUTs */ + out_y = 0; + for (r = 0; r < MAX_REGIONS; r++) { + if (this->dvbsub->regions[r].win >= 0) { + if (this->dvbsub->page.regions[r].is_visible) { + + out_y = this->dvbsub->page.regions[r].y * 720; + for (y = 0; y < this->dvbsub->regions[r].height; y++) { + for (x = 0; x < this->dvbsub->regions[r].width; x++) { + this->bitmap[out_y + x + this->dvbsub->page.regions[r].x] = this->dvbsub->regions[r].img[(y * this->dvbsub->regions[r].width) + x]; + if (this->bitmap[out_y + x + this->dvbsub->page.regions[r].x]) + { + display=1; + } + } + out_y += 720; + } + } + } + } + + if(display){ + + /* start timer thread if stopped */ + if(this->dvbsub_timer_stop){ + this->dvbsub_timer_stop=0; + if (pthread_create(&this->dvbsub_timer_thread, NULL, dvbsub_timer_func, this) != 0) { + xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, _("dvbsub: cannot create timer thread\n")); + } + } + + /* display immediately at requested PTS*/ + this->stream->osd_renderer->set_palette(this->osd,(uint32_t *)this->dvbsub->colours,this->dvbsub->trans); + this->stream->osd_renderer->draw_bitmap (this->osd,this->bitmap, 1,1,720,576,NULL); + + pthread_mutex_lock(&this->dvbsub_timer_mutex); + this->stream->osd_renderer->show (this->osd, this->vpts); + /* reset the timer thread */ + this->dvbsub_timer_tcount=0; + pthread_mutex_unlock(&this->dvbsub_timer_mutex); + } +} + + +static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) +{ + dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; + int new_i; + int data_identifier, subtitle_stream_id; + int segment_length, segment_type; + int PES_header_data_length; + int PES_packet_length; + int r; + + if((buf->type & 0xffff0000)!=BUF_SPU_DVB) + return; + + if (buf->decoder_flags & BUF_FLAG_SPECIAL) { + if (buf->decoder_info[1] == BUF_SPECIAL_SPU_DVB_DESCRIPTOR) { + if (buf->decoder_info[2] == 0) { + this->dvbsub_timer_stop=1; + this->stream->osd_renderer->hide (this->osd, 0); + } + else { + xine_fast_memcpy (this->spu_descriptor, buf->decoder_info_ptr[2], buf->decoder_info[2]); + } + } + return; + } + else { + if (buf->decoder_info[2]) { + memset (this->pes_pkt, 0xff, 64*1024); + this->pes_pkt_wrptr = this->pes_pkt; + this->pes_pkt_size = buf->decoder_info[2]; + this->pts = buf->pts; + + xine_fast_memcpy (this->pes_pkt, buf->content, buf->size); + this->pes_pkt_wrptr += buf->size; + } + else { + if (this->pes_pkt && (this->pes_pkt_wrptr != this->pes_pkt)) { + xine_fast_memcpy (this->pes_pkt_wrptr, buf->content, buf->size); + this->pes_pkt_wrptr += buf->size; + } + } + } + /* inform metronom we've received the package */ + if (buf->pts) { + metronom_t *metronom = this->stream->metronom; + this->vpts = metronom->got_spu_packet (metronom, buf->pts); + } + + /* process the pes section */ + + PES_packet_length = this->pes_pkt_size; + + this->dvbsub->buf = this->pes_pkt; + + PES_header_data_length = 0; + this->dvbsub->i = 0; + + data_identifier = this->dvbsub->buf[this->dvbsub->i++]; + subtitle_stream_id = this->dvbsub->buf[this->dvbsub->i++]; + + while (this->dvbsub->i <= (PES_packet_length)) { + /* SUBTITLING SEGMENT */ + this->dvbsub->i++; + segment_type = this->dvbsub->buf[this->dvbsub->i++]; + + this->dvbsub->page.page_id = (this->dvbsub->buf[this->dvbsub->i] << 8) | this->dvbsub->buf[this->dvbsub->i + 1]; + segment_length = (this->dvbsub->buf[this->dvbsub->i + 2] << 8) | this->dvbsub->buf[this->dvbsub->i + 3]; + new_i = this->dvbsub->i + segment_length + 4; + + /* only process complete segments */ + if(new_i > (this->pes_pkt_wrptr - this->pes_pkt)) + break; + /* verify we've the right segment */ + if(this->dvbsub->page.page_id==this->spu_descriptor->comp_page_id){ + /* SEGMENT_DATA_FIELD */ + switch (segment_type & 0xff) { + case 0x10: + process_page_composition_segment (this); + break; + case 0x11: + process_region_composition_segment (this); + break; + case 0x12: + process_CLUT_definition_segment(this); + break; + case 0x13: + process_object_data_segment (this); + break; + case 0x80: /* Page is now completely rendered */ + for (r=0;rdvbsub->regions[r].img, 15, sizeof (this->dvbsub->regions[r].img)); + this->dvbsub->page.regions[r].is_visible=0; + this->dvbsub->regions[r].win = -1; + } + break; + default: + return; + break; + } + draw_subtitles(this); + } + this->dvbsub->i = new_i; + } + + return; +} + +static void spudec_reset (spu_decoder_t * this_gen) +{ + dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; + + if (this->osd) + this->stream->osd_renderer->hide (this->osd, 0); + +} + +static void spudec_discontinuity (spu_decoder_t * this_gen) +{ + /* do nothing */ +} + +static void spudec_dispose (spu_decoder_t * this_gen) +{ + dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; + + if(!this->dvbsub_timer_stop){ + this->dvbsub_timer_stop=1; + } + + if(this->spu_descriptor){ + free(this->spu_descriptor); + this->spu_descriptor=NULL; + } + + if (this->osd) { + this->stream->osd_renderer->free_object (this->osd); + this->osd = NULL; + } + + if (this->pes_pkt) + free (this->pes_pkt); + + if (this->bitmap) + free (this->bitmap); + + if (this->dvbsub) + free (this->dvbsub); + + free (this); +} + +static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen, xine_stream_t * stream) +{ + + int i; + dvb_spu_decoder_t *this; + dvb_spu_class_t *class = (dvb_spu_class_t *) class_gen; + + this = (dvb_spu_decoder_t *) xine_xmalloc (sizeof (dvb_spu_decoder_t)); + + this->spu_decoder.decode_data = spudec_decode_data; + this->spu_decoder.reset = spudec_reset; + this->spu_decoder.discontinuity = spudec_discontinuity; + this->spu_decoder.dispose = spudec_dispose; + this->spu_decoder.get_interact_info = NULL; + this->spu_decoder.set_button = NULL; + + this->class = class; + this->stream = stream; + + this->pes_pkt = xine_xmalloc (1024*65); + this->bitmap = xine_xmalloc (720*576); + this->spu_descriptor = xine_xmalloc(sizeof(spu_dvb_descriptor_t)); + + this->dvbsub = xine_xmalloc (sizeof (dvbsub_func_t)); + + for (i = 0; i < MAX_REGIONS; i++) { + this->dvbsub->page.regions[i].is_visible = 0; + this->dvbsub->regions[i].win = -1; + } + + this->osd = this->stream->osd_renderer->new_object (this->stream->osd_renderer, 720, 600); + this->stream->osd_renderer->set_position (this->osd, 1, 1); + this->stream->osd_renderer->set_font (this->osd, "cetus", 26); + this->stream->osd_renderer->set_encoding (this->osd, NULL); + this->stream->osd_renderer->set_text_palette (this->osd, TEXTPALETTE_YELLOW_BLACK_TRANSPARENT, OSD_TEXT1); + + + /* subtitle timer thread. */ + this->dvbsub_timer_stop = 1; + + return (spu_decoder_t *) this; +} + +static void dvb_spu_class_dispose (spu_decoder_class_t * this) +{ + free (this); +} + +static char *dvb_spu_class_get_identifier (spu_decoder_class_t * this) +{ + return "spudvb"; +} + +static char *dvb_spu_class_get_description (spu_decoder_class_t * this) +{ + return "DVB subtitle decoder plugin"; +} + +static void *init_spu_decoder_plugin (xine_t * xine, void *data) +{ + + dvb_spu_class_t *this; + this = (dvb_spu_class_t *) xine_xmalloc (sizeof (dvb_spu_class_t)); + + this->class.open_plugin = dvb_spu_class_open_plugin; + this->class.get_identifier = dvb_spu_class_get_identifier; + this->class.get_description = dvb_spu_class_get_description; + this->class.dispose = dvb_spu_class_dispose; + + this->xine = xine; + + return &this->class; +} + + +/* plugin catalog information */ +static uint32_t supported_types[] = { BUF_SPU_DVB, 0 }; + +static const decoder_info_t spudec_info = { + supported_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { +/* type, API, "name", version, special_info, init_function */ + {PLUGIN_SPU_DECODER, 16, "spudvb", XINE_VERSION_CODE, &spudec_info, + &init_spu_decoder_plugin}, + {PLUGIN_NONE, 0, "", 0, NULL, NULL} +}; -- cgit v1.2.3 From cf701273878fafeef78183bac35576de902f78f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:50:17 +0200 Subject: Rename xine_decoder.c to xine_sputext_decoder.c. Use xineplug_LTLIBRARIES. --HG-- rename : src/libsputext/xine_decoder.c => src/libsputext/xine_sputext_decoder.c --- src/libsputext/Makefile.am | 10 +- src/libsputext/xine_decoder.c | 1019 --------------------------------- src/libsputext/xine_sputext_decoder.c | 1019 +++++++++++++++++++++++++++++++++ 3 files changed, 1022 insertions(+), 1026 deletions(-) delete mode 100644 src/libsputext/xine_decoder.c create mode 100644 src/libsputext/xine_sputext_decoder.c (limited to 'src') diff --git a/src/libsputext/Makefile.am b/src/libsputext/Makefile.am index 362f9319e..5e4ce59d0 100644 --- a/src/libsputext/Makefile.am +++ b/src/libsputext/Makefile.am @@ -1,17 +1,13 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) +AM_LDFLAGS = $(xineplug_ldflags) -sputext_decoder = xineplug_decode_sputext.la xineplug_dmx_sputext.la - -lib_LTLIBRARIES = $(sputext_decoder) +xineplug_LTLIBRARIES = xineplug_decode_sputext.la xineplug_dmx_sputext.la xineplug_dmx_sputext_la_SOURCES = demux_sputext.c xineplug_dmx_sputext_la_LIBADD = $(XINE_LIB) xineplug_dmx_sputext_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_dmx_sputext_la_LDFLAGS = -avoid-version -module -xineplug_decode_sputext_la_SOURCES = xine_decoder.c +xineplug_decode_sputext_la_SOURCES = xine_sputext_decoder.c xineplug_decode_sputext_la_LIBADD = $(XINE_LIB) xineplug_decode_sputext_la_CFLAGS = $(VISIBILITY_FLAG) -xineplug_decode_sputext_la_LDFLAGS = -avoid-version -module diff --git a/src/libsputext/xine_decoder.c b/src/libsputext/xine_decoder.c deleted file mode 100644 index e8ef631ca..000000000 --- a/src/libsputext/xine_decoder.c +++ /dev/null @@ -1,1019 +0,0 @@ -/* - * Copyright (C) 2000-2004 the xine project - * - * This file is part of xine, a free 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: xine_decoder.c,v 1.99 2007/02/20 01:04:07 dgp85 Exp $ - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "libsputext" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "buffer.h" -#include "xine_internal.h" -#include "xineutils.h" -#include "osd.h" - -#define SUB_MAX_TEXT 5 /* lines */ -#define SUB_BUFSIZE 256 /* chars per line */ - - -typedef enum { - SUBTITLE_SIZE_TINY = 0, - SUBTITLE_SIZE_SMALL, - SUBTITLE_SIZE_NORMAL, - SUBTITLE_SIZE_LARGE, - SUBTITLE_SIZE_VERY_LARGE, - SUBTITLE_SIZE_HUGE, - - SUBTITLE_SIZE_NUM /* number of values in enum */ -} subtitle_size; - -#define FONTNAME_SIZE 100 - -typedef struct sputext_class_s { - spu_decoder_class_t class; - - subtitle_size subtitle_size; /* size of subtitles */ - int vertical_offset; - char font[FONTNAME_SIZE]; /* subtitle font */ -#ifdef HAVE_FT2 - char font_ft[FILENAME_MAX]; /* subtitle font */ - int use_font_ft; /* use Freetype */ -#endif - char *src_encoding; /* encoding of subtitle file */ - int use_unscaled; /* use unscaled OSD if possible */ - - xine_t *xine; - -} sputext_class_t; - - -typedef struct sputext_decoder_s { - spu_decoder_t spu_decoder; - - sputext_class_t *class; - xine_stream_t *stream; - - int ogm; - int lines; - char text[SUB_MAX_TEXT][SUB_BUFSIZE]; - - /* below 3 variables are the same from class. use to detect - * when something changes. - */ - subtitle_size subtitle_size; /* size of subtitles */ - int vertical_offset; - char font[FILENAME_MAX]; /* subtitle font */ - char *buf_encoding; /* encoding of subtitle buffer */ - - int width; /* frame width */ - int height; /* frame height */ - int font_size; - int line_height; - int started; - int finished; - - osd_renderer_t *renderer; - osd_object_t *osd; - - int64_t img_duration; - int64_t last_subtitle_end; /* no new subtitle before this vpts */ - int unscaled; /* use unscaled OSD */ - - int last_lines; /* number of lines of the previous subtitle */ -} sputext_decoder_t; - -static inline char *get_font (sputext_class_t *class) -{ -#ifdef HAVE_FT2 - return class->use_font_ft ? class->font_ft : class->font; -#else - return class->font; -#endif -} - -static void update_font_size (sputext_decoder_t *this, int force_update) { - static int sizes[SUBTITLE_SIZE_NUM] = { 16, 20, 24, 32, 48, 64 }; - - int y; - - if ((this->subtitle_size != this->class->subtitle_size) || - (this->vertical_offset != this->class->vertical_offset) || - force_update) { - - this->subtitle_size = this->class->subtitle_size; - this->vertical_offset = this->class->vertical_offset; - this->last_lines = 0; - - this->font_size = sizes[this->class->subtitle_size]; - - this->line_height = this->font_size + 10; - - y = this->height - (SUB_MAX_TEXT * this->line_height) - 5; - - if(((y - this->class->vertical_offset) >= 0) && ((y - this->class->vertical_offset) <= this->height)) - y -= this->class->vertical_offset; - - if( this->osd ) - this->renderer->free_object (this->osd); - - lprintf("new osd object, width %d, height %d*%d\n", this->width, SUB_MAX_TEXT, this->line_height); - this->osd = this->renderer->new_object (this->renderer, - this->width, - SUB_MAX_TEXT * this->line_height); - - this->renderer->set_font (this->osd, get_font (this->class), this->font_size); - this->renderer->set_position (this->osd, 0, y); - } -} - -static void update_output_size (sputext_decoder_t *this) { - int unscaled; - - unscaled = this->class->use_unscaled && - (this->stream->video_out->get_capabilities(this->stream->video_out) & - VO_CAP_UNSCALED_OVERLAY); - - if( unscaled != this->unscaled ) { - this->unscaled = unscaled; - this->width = 0; /* force update */ - } - - /* initialize decoder if needed */ - if( this->unscaled ) { - if( this->width != this->stream->video_out->get_property(this->stream->video_out, - VO_PROP_WINDOW_WIDTH) || - this->height != this->stream->video_out->get_property(this->stream->video_out, - VO_PROP_WINDOW_HEIGHT) || - !this->img_duration || !this->osd ) { - - int width = 0, height = 0; /* dummy */ - - this->stream->video_out->status(this->stream->video_out, NULL, - &width, &height, &this->img_duration ); - if( width && height ) { - - this->width = this->stream->video_out->get_property(this->stream->video_out, - VO_PROP_WINDOW_WIDTH); - this->height = this->stream->video_out->get_property(this->stream->video_out, - VO_PROP_WINDOW_HEIGHT); - - if(!this->osd || (this->width && this->height)) { - this->renderer = this->stream->osd_renderer; - - update_font_size (this, 1); - } - } - } - } else { - if( !this->width || !this->height || !this->img_duration || !this->osd ) { - - this->width = 0; - this->height = 0; - - this->stream->video_out->status(this->stream->video_out, NULL, - &this->width, &this->height, &this->img_duration ); - - if(!this->osd || ( this->width && this->height)) { - this->renderer = this->stream->osd_renderer; - - update_font_size (this, 1); - } - } - } -} - -static int parse_utf8_size(unsigned char *c) -{ - if ( c[0]<0x80 ) - return 1; - - if( c[1]==0 ) - return 1; - if ( (c[0]>=0xC2 && c[0]<=0xDF) && (c[1]>=0x80 && c[1]<=0xBF) ) - return 2; - - if( c[2]==0 ) - return 2; - else if ( c[0]==0xE0 && (c[1]>=0xA0 && c[1]<=0xBF) && (c[2]>=0x80 && c[1]<=0xBF) ) - return 3; - else if ( (c[0]>=0xE1 && c[0]<=0xEC) && (c[1]>=0x80 && c[1]<=0xBF) && (c[2]>=0x80 && c[1]<=0xBF) ) - return 3; - else if ( c[0]==0xED && (c[1]>=0x80 && c[1]<=0x9F) && (c[2]>=0x80 && c[1]<=0xBF) ) - return 3; - else if ( c[0]==0xEF && (c[1]>=0xA4 && c[1]<=0xBF) && (c[2]>=0x80 && c[1]<=0xBF) ) - return 3; - else - return 1; -} - -static int ogm_get_width(sputext_decoder_t *this, char* text) { - int i=0,width=0,w,dummy; - char letter[5]={0, 0, 0, 0, 0}; - int shift, isutf8 = 0; - char *encoding = (this->buf_encoding)?this->buf_encoding: - this->class->src_encoding; - if( strcmp(encoding, "utf-8") == 0 ) - isutf8 = 1; - - while (i<=strlen(text)) { - switch (text[i]) { - case '<': - if (!strncmp("", text+i, 3)) { - /*Do somethink to enable BOLD typeface*/ - i=i+3; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable BOLD typeface*/ - i=i+4; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to enable italics typeface*/ - i=i+3; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable italics typeface*/ - i=i+4; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable typing - fixme - no teststreams*/ - i=i+6; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to enable typing - fixme - no teststreams*/ - i=i+7; - break; - } -default: - if ( isutf8 ) - shift = parse_utf8_size(&text[i]); - else - shift = 1; - memcpy(letter,&text[i],shift); - letter[shift]=0; - - this->renderer->get_text_size(this->osd, letter, &w, &dummy); - width=width+w; - i+=shift; - } - } - - return width; -} - -static void ogm_render_line(sputext_decoder_t *this, int x, int y, char* text) { - int i=0,w,dummy; - char letter[5]={0, 0, 0, 0, 0}; - int shift, isutf8 = 0; - char *encoding = (this->buf_encoding)?this->buf_encoding: - this->class->src_encoding; - if( strcmp(encoding, "utf-8") == 0 ) - isutf8 = 1; - - while (i<=strlen(text)) { - switch (text[i]) { - case '<': - if (!strncmp("", text+i, 3)) { - /*Do somethink to enable BOLD typeface*/ - i=i+3; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable BOLD typeface*/ - i=i+4; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to enable italics typeface*/ - i=i+3; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable italics typeface*/ - i=i+4; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to disable typing - fixme - no teststreams*/ - i=i+6; - break; - } else if (!strncmp("", text+i, 3)) { - /*Do somethink to enable typing - fixme - no teststreams*/ - i=i+7; - break; - } - default: - if ( isutf8 ) - shift = parse_utf8_size(&text[i]); - else - shift = 1; - memcpy(letter,&text[i],shift); - letter[shift]=0; - - this->renderer->render_text(this->osd, x, y, letter, OSD_TEXT1); - this->renderer->get_text_size(this->osd, letter, &w, &dummy); - x=x+w; - i+=shift; - } - } -} - -static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t sub_end ) { - - int line, y; - int font_size; - char *font; - - _x_assert(this->renderer != NULL); - if ( ! this->renderer ) - return; - - update_font_size(this, 0); - - font = get_font (this->class); - if( strcmp(this->font, font) ) { - strncpy(this->font, font, FILENAME_MAX); - this->font[FILENAME_MAX - 1] = '\0'; - this->renderer->set_font (this->osd, font, this->font_size); - } - - font_size = this->font_size; - if (this->buf_encoding) - this->renderer->set_encoding(this->osd, this->buf_encoding); - else - this->renderer->set_encoding(this->osd, this->class->src_encoding); - - for (line = 0; line < this->lines; line++) /* first, check lenghts and word-wrap if needed */ - { - int w, h; - if( this->ogm ) - w = ogm_get_width( this, this->text[line]); - else - this->renderer->get_text_size( this->osd, this->text[line], &w, &h); - if( w > this->width ) { /* line is too long */ - int chunks=(int)(w/this->width)+(w%this->width?1:0); - if( this->lines+chunks <= SUB_MAX_TEXT && chunks>1 ) { /* try adding newlines while keeping existing ones */ - int a; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,"Partial subtitle line splitting in %i chunks\n",chunks); - for(a=this->lines-1;a>=0;a--) { - if(a>line) /* lines after the too-long one */ - memcpy(this->text[a+chunks-1],this->text[a],SUB_BUFSIZE); - else if(a==line) { /* line to be splitted */ - int b,len=strlen(this->text[line]); - char *p=this->text[line]; - for(b=0;btext[line+b],p,SUB_BUFSIZE); - this->text[line+b][SUB_BUFSIZE - 1] = '\0'; - } else { - for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); - if(*c==' ') { - *c='\0'; - if(b) { /* we are reading something that has to be moved to another line */ - strncpy(this->text[line+b],p,SUB_BUFSIZE); - this->text[line+b][SUB_BUFSIZE - 1] = '\0'; - } - p=c+1; - } - } - } - } - } - this->lines+=chunks-1; - } else { /* regenerate all the lines to find something that better fits */ - char buf[SUB_BUFSIZE*SUB_MAX_TEXT]; - int a,w,h,chunks; - buf[0]='\0'; - for(a=0;alines;a++) { - if(a) { - int len=strlen(buf); - buf[len]=' '; - buf[len+1]='\0'; - } - strcat(buf,this->text[a]); - } - if( this->ogm ) - w = ogm_get_width( this, buf); - else - this->renderer->get_text_size( this->osd, buf, &w, &h); - chunks=(int)(w/this->width)+(w%this->width?1:0); - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Complete subtitle line splitting in %i chunks\n",chunks); - if(chunks<=SUB_MAX_TEXT) {/* if the length is over than SUB_MAX_TEXT*this->width nothing can be done */ - int b,len=strlen(buf); - char *p=buf; - for(b=0;btext[b],p,SUB_BUFSIZE); - this->text[b][SUB_BUFSIZE - 1] = '\0'; - } else { - for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); - if(*c==' ') { - *c='\0'; - strncpy(this->text[b],p,SUB_BUFSIZE); - this->text[b][SUB_BUFSIZE - 1] = '\0'; - p=c+1; - } - } - } - this->lines=chunks; - } else - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Subtitle too long to be splited\n"); - line=this->lines; - } - } - } - - font_size = this->font_size; - if (this->buf_encoding) - this->renderer->set_encoding(this->osd, this->buf_encoding); - else - this->renderer->set_encoding(this->osd, this->class->src_encoding); - - for (line = 0; line < this->lines; line++) /* first, check lenghts and word-wrap if needed */ - { - int w, h; - if( this->ogm ) - w = ogm_get_width( this, this->text[line]); - else - this->renderer->get_text_size( this->osd, this->text[line], &w, &h); - if( w > this->width ) { /* line is too long */ - int chunks=(int)(w/this->width)+(w%this->width?1:0); - if( this->lines+chunks <= SUB_MAX_TEXT && chunks>1 ) { /* try adding newlines while keeping existing ones */ - int a; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,"Partial subtitle line splitting in %i chunks\n",chunks); - for(a=this->lines-1;a>=0;a--) { - if(a>line) /* lines after the too-long one */ - memcpy(this->text[a+chunks-1],this->text[a],SUB_BUFSIZE); - else if(a==line) { /* line to be splitted */ - int b,len=strlen(this->text[line]); - char *p=this->text[line]; - for(b=0;btext[line+b],p,SUB_BUFSIZE); - this->text[line+b][SUB_BUFSIZE - 1] = '\0'; - } else { - for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); - if(*c==' ') { - *c='\0'; - if(b) { /* we are reading something that has to be moved to another line */ - strncpy(this->text[line+b],p,SUB_BUFSIZE); - this->text[line+b][SUB_BUFSIZE - 1] = '\0'; - } - p=c+1; - } - } - } - } - } - this->lines+=chunks-1; - } else { /* regenerate all the lines to find something that better fits */ - char buf[SUB_BUFSIZE*SUB_MAX_TEXT]; - int a,w,h,chunks; - buf[0]='\0'; - for(a=0;alines;a++) { - if(a) { - int len=strlen(buf); - buf[len]=' '; - buf[len+1]='\0'; - } - strcat(buf,this->text[a]); - } - if( this->ogm ) - w = ogm_get_width( this, buf); - else - this->renderer->get_text_size( this->osd, buf, &w, &h); - chunks=(int)(w/this->width)+(w%this->width?1:0); - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Complete subtitle line splitting in %i chunks\n",chunks); - if(chunks<=SUB_MAX_TEXT) {/* if the length is over than SUB_MAX_TEXT*this->width nothing can be done */ - int b,len=strlen(buf); - char *p=buf; - for(b=0;btext[b],p,SUB_BUFSIZE); - this->text[b][SUB_BUFSIZE - 1] = '\0'; - } else { - for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); - if(*c==' ') { - *c='\0'; - strncpy(this->text[b],p,SUB_BUFSIZE); - this->text[b][SUB_BUFSIZE - 1] = '\0'; - p=c+1; - } - } - } - this->lines=chunks; - } else - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Subtitle too long to be splited\n"); - line=this->lines; - } - } - } - - if (this->last_lines) - this->renderer->filled_rect (this->osd, 0, this->line_height * (SUB_MAX_TEXT - this->last_lines), - this->width - 1, this->line_height * SUB_MAX_TEXT - 1, 0); - this->last_lines = this->lines; - y = (SUB_MAX_TEXT - this->lines) * this->line_height; - - for (line = 0; line < this->lines; line++) { - int w, h, x; - - while(1) { - if( this->ogm ) - w = ogm_get_width( this, this->text[line]); - else - this->renderer->get_text_size( this->osd, this->text[line], - &w, &h); - x = (this->width - w) / 2; - - if( w > this->width && font_size > 16 ) { - font_size -= 4; - this->renderer->set_font (this->osd, get_font (this->class), font_size); - } else { - break; - } - } - - if( this->ogm ) { - ogm_render_line(this, x, y + line*this->line_height, this->text[line]); - } else { - this->renderer->render_text (this->osd, x, y + line * this->line_height, - this->text[line], OSD_TEXT1); - } - } - - if( font_size != this->font_size ) - this->renderer->set_font (this->osd, get_font (this->class), this->font_size); - - if( this->last_subtitle_end && sub_start < this->last_subtitle_end ) { - sub_start = this->last_subtitle_end; - } - this->last_subtitle_end = sub_end; - - this->renderer->set_text_palette (this->osd, -1, OSD_TEXT1); - - if (this->unscaled) - this->renderer->show_unscaled (this->osd, sub_start); - else - this->renderer->show (this->osd, sub_start); - - this->renderer->hide (this->osd, sub_end); - - lprintf ("scheduling subtitle >%s< at %"PRId64" until %"PRId64", current time is %"PRId64"\n", - this->text[0], sub_start, sub_end, - this->stream->xine->clock->get_current_time (this->stream->xine->clock)); -} - - -static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { - - sputext_decoder_t *this = (sputext_decoder_t *) this_gen; - int uses_time; - int32_t start, end, diff; - int64_t start_vpts, end_vpts; - int64_t spu_offset; - int i; - uint32_t *val; - char *str; - extra_info_t extra_info; - int master_status, slave_status; - int vo_discard; - - /* filter unwanted streams */ - if (buf->decoder_flags & BUF_FLAG_HEADER) { - return; - } - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if ((this->stream->spu_channel & 0x1f) != (buf->type & 0x1f)) - return; - - if ( (buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_CHARSET_ENCODING) ) - this->buf_encoding = buf->decoder_info_ptr[2]; - else - this->buf_encoding = NULL; - - if( (buf->type & 0xFFFF0000) == BUF_SPU_OGM ) { - - this->ogm = 1; - uses_time = 1; - val = (uint32_t * )buf->content; - start = *val++; - end = *val++; - str = (char *)val; - - if (!*str) return; - /* Empty ogm packets (as created by ogmmux) clears out old messages. We already respect the end time. */ - - this->lines = 0; - - i = 0; - while (*str && (this->lines < SUB_MAX_TEXT) && (i < SUB_BUFSIZE)) { - if (*str == '\r' || *str == '\n') { - if (i) { - this->text[ this->lines ][i] = 0; - this->lines++; - i = 0; - } - } else { - this->text[ this->lines ][i] = *str; - if (i < SUB_BUFSIZE-1) - i++; - } - str++; - } - if (i == SUB_BUFSIZE) - i--; - - if (i) { - this->text[ this->lines ][i] = 0; - this->lines++; - } - - } else { - - this->ogm = 0; - val = (uint32_t * )buf->content; - - this->lines = *val++; - uses_time = *val++; - start = *val++; - end = *val++; - str = (char *)val; - for (i = 0; i < this->lines; i++, str += strlen(str) + 1) { - strncpy( this->text[i], str, SUB_BUFSIZE - 1); - this->text[i][SUB_BUFSIZE - 1] = '\0'; - } - - } - - xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, - "libsputext: decoder data [%s]\n", this->text[0]); - xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, - "libsputext: mode %d timing %d->%d\n", uses_time, start, end); - - if( end <= start ) { - xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, - "libsputext: discarding subtitle with invalid timing\n"); - return; - } - - spu_offset = this->stream->master->metronom->get_option (this->stream->master->metronom, - METRONOM_SPU_OFFSET); - if( uses_time ) { - start += (spu_offset / 90); - end += (spu_offset / 90); - } else { - if( this->osd && this->img_duration ) { - start += spu_offset / this->img_duration; - end += spu_offset / this->img_duration; - } - } - - while( !this->finished ) { - - master_status = xine_get_status (this->stream->master); - slave_status = xine_get_status (this->stream); - vo_discard = this->stream->video_out->get_property(this->stream->video_out, - VO_PROP_DISCARD_FRAMES); - - _x_get_current_info (this->stream->master, &extra_info, sizeof(extra_info) ); - - lprintf("master: %d slave: %d input_normpos: %d vo_discard: %d\n", - master_status, slave_status, extra_info.input_normpos, vo_discard); - - if( !this->started && (master_status == XINE_STATUS_PLAY && - slave_status == XINE_STATUS_PLAY && - extra_info.input_normpos) ) { - lprintf("started\n"); - - this->width = this->height = 0; - this->started = 1; - - update_output_size( this ); - } - - if( this->started ) { - - if( master_status != XINE_STATUS_PLAY || - slave_status != XINE_STATUS_PLAY || - vo_discard ) { - lprintf("finished\n"); - - this->width = this->height = 0; - this->finished = 1; - return; - } - - if( this->osd ) { - - /* try to use frame number mode */ - if( !uses_time && extra_info.frame_number ) { - - diff = end - extra_info.frame_number; - - /* discard old subtitles */ - if( diff < 0 ) { - xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, - "libsputext: discarding old subtitle\n"); - return; - } - - diff = start - extra_info.frame_number; - - start_vpts = extra_info.vpts + diff * this->img_duration; - end_vpts = start_vpts + (end-start) * this->img_duration; - - } else { - - if( !uses_time ) { - start = start * this->img_duration / 90; - end = end * this->img_duration / 90; - uses_time = 1; - } - - diff = end - extra_info.input_time; - - /* discard old subtitles */ - if( diff < 0 ) { - xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, - "libsputext: discarding old subtitle\n"); - return; - } - - diff = start - extra_info.input_time; - - start_vpts = extra_info.vpts + diff * 90; - end_vpts = start_vpts + (end-start) * 90; - } - - _x_spu_decoder_sleep(this->stream, start_vpts); - update_output_size( this ); - draw_subtitle(this, start_vpts, end_vpts); - - return; - } - } - - if (_x_spu_decoder_sleep(this->stream, 0)) - xine_usec_sleep (50000); - else - return; - } -} - - -static void spudec_reset (spu_decoder_t *this_gen) { - sputext_decoder_t *this = (sputext_decoder_t *) this_gen; - - lprintf("i guess we just seeked\n"); - this->width = this->height = 0; - this->started = this->finished = 0; - this->last_subtitle_end = 0; -} - -static void spudec_discontinuity (spu_decoder_t *this_gen) { - /* sputext_decoder_t *this = (sputext_decoder_t *) this_gen; */ - -} - -static void spudec_dispose (spu_decoder_t *this_gen) { - sputext_decoder_t *this = (sputext_decoder_t *) this_gen; - - if (this->osd) { - this->renderer->free_object (this->osd); - this->osd = NULL; - } - free(this); -} - -static void update_vertical_offset(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - class->vertical_offset = entry->num_value; -} - -static void update_osd_font(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - strncpy(class->font, entry->str_value, FONTNAME_SIZE); - class->font[FONTNAME_SIZE - 1] = '\0'; - - xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_font = %s\n", class->font ); -} - -#ifdef HAVE_FT2 -static void update_osd_font_ft(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - strncpy(class->font_ft, entry->str_value, FILENAME_MAX); - class->font_ft[FILENAME_MAX - 1] = '\0'; - - xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_font_ft = %s\n", class->font_ft); -} - -static void update_osd_use_font_ft(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - class->use_font_ft = entry->num_value; - - xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_use_font_ft = %d\n", class->use_font_ft); -} -#endif - -static void update_subtitle_size(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - class->subtitle_size = entry->num_value; -} - -static void update_use_unscaled(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - class->use_unscaled = entry->num_value; -} - -static spu_decoder_t *sputext_class_open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { - - sputext_class_t *class = (sputext_class_t *)class_gen; - sputext_decoder_t *this ; - - this = (sputext_decoder_t *) xine_xmalloc (sizeof (sputext_decoder_t)); - - this->spu_decoder.decode_data = spudec_decode_data; - this->spu_decoder.reset = spudec_reset; - this->spu_decoder.discontinuity = spudec_discontinuity; - this->spu_decoder.get_interact_info = NULL; - this->spu_decoder.set_button = NULL; - this->spu_decoder.dispose = spudec_dispose; - - this->class = class; - this->stream = stream; - - return (spu_decoder_t *) this; -} - -static void sputext_class_dispose (spu_decoder_class_t *class_gen) { - sputext_class_t *this = (sputext_class_t *)class_gen; - - this->xine->config->unregister_callback(this->xine->config, - "subtitles.separate.src_encoding"); - this->xine->config->unregister_callback(this->xine->config, - "subtitles.separate.subtitle_size"); - this->xine->config->unregister_callback(this->xine->config, - "subtitles.separate.vertical_offset"); - this->xine->config->unregister_callback(this->xine->config, - "subtitles.separate.use_unscaled_osd"); - free (this); -} - -static char *sputext_class_get_identifier (spu_decoder_class_t *this) { - return "sputext"; -} - -static char *sputext_class_get_description (spu_decoder_class_t *this) { - return "external subtitle decoder plugin"; -} - -static void update_src_encoding(void *class_gen, xine_cfg_entry_t *entry) -{ - sputext_class_t *class = (sputext_class_t *)class_gen; - - class->src_encoding = entry->str_value; - xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_src_encoding = %s\n", class->src_encoding ); -} - -static void *init_spu_decoder_plugin (xine_t *xine, void *data) { - - static const char *subtitle_size_strings[] = { - "tiny", "small", "normal", "large", "very large", "huge", NULL - }; - sputext_class_t *this ; - - lprintf("init class\n"); - - this = (sputext_class_t *) xine_xmalloc (sizeof (sputext_class_t)); - - this->class.open_plugin = sputext_class_open_plugin; - this->class.get_identifier = sputext_class_get_identifier; - this->class.get_description = sputext_class_get_description; - this->class.dispose = sputext_class_dispose; - - this->xine = xine; - - this->subtitle_size = xine->config->register_enum(xine->config, - "subtitles.separate.subtitle_size", - 1, - subtitle_size_strings, - _("subtitle size"), - _("You can adjust the subtitle size here. The setting will " - "be evaluated relative to the window size."), - 0, update_subtitle_size, this); - this->vertical_offset = xine->config->register_num(xine->config, - "subtitles.separate.vertical_offset", - 0, - _("subtitle vertical offset"), - _("You can adjust the vertical position of the subtitle. " - "The setting will be evaluated relative to the window size."), - 0, update_vertical_offset, this); - strncpy(this->font, xine->config->register_string(xine->config, - "subtitles.separate.font", - "sans", - _("font for subtitles"), - _("A font from the xine font directory to be used for the " - "subtitle text."), - 10, update_osd_font, this), FONTNAME_SIZE); - this->font[FONTNAME_SIZE - 1] = '\0'; -#ifdef HAVE_FT2 - strncpy(this->font_ft, xine->config->register_filename(xine->config, - "subtitles.separate.font_freetype", - "", XINE_CONFIG_STRING_IS_FILENAME, - _("font for subtitles"), - _("An outline font file (e.g. a .ttf) to be used for the subtitle text."), - 10, update_osd_font_ft, this), FILENAME_MAX); - this->font_ft[FILENAME_MAX - 1] = '\0'; - this->use_font_ft = xine->config->register_bool(xine->config, - "subtitles.separate.font_use_freetype", - 0, - _("whether to use a freetype font"), - NULL, - 10, update_osd_use_font_ft, this); -#endif - this->src_encoding = xine->config->register_string(xine->config, - "subtitles.separate.src_encoding", - xine_guess_spu_encoding(), - _("encoding of the subtitles"), - _("The encoding of the subtitle text in the stream. This setting " - "is used to render non-ASCII characters correctly. If non-ASCII " - "characters are not displayed as you expect, ask the " - "creator of the subtitles what encoding was used."), - 10, update_src_encoding, this); - this->use_unscaled = xine->config->register_bool(xine->config, - "subtitles.separate.use_unscaled_osd", - 1, - _("use unscaled OSD if possible"), - _("The unscaled OSD will be rendered independently of the video " - "frame and will always be sharp, even if the video is magnified. " - "This will look better, but does not work with all graphics " - "hardware. The alternative is the scaled OSD, which will become " - "blurry, if you enlarge a low resolution video to fullscreen, but " - "it works with all graphics cards."), - 10, update_use_unscaled, this); - - return &this->class; -} - - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_SPU_TEXT, BUF_SPU_OGM, 0 }; - -static const decoder_info_t spudec_info = { - supported_types, /* supported types */ - 1 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_SPU_DECODER | PLUGIN_MUST_PRELOAD, 16, "sputext", XINE_VERSION_CODE, &spudec_info, &init_spu_decoder_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c new file mode 100644 index 000000000..e8ef631ca --- /dev/null +++ b/src/libsputext/xine_sputext_decoder.c @@ -0,0 +1,1019 @@ +/* + * Copyright (C) 2000-2004 the xine project + * + * This file is part of xine, a free 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: xine_decoder.c,v 1.99 2007/02/20 01:04:07 dgp85 Exp $ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "libsputext" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "buffer.h" +#include "xine_internal.h" +#include "xineutils.h" +#include "osd.h" + +#define SUB_MAX_TEXT 5 /* lines */ +#define SUB_BUFSIZE 256 /* chars per line */ + + +typedef enum { + SUBTITLE_SIZE_TINY = 0, + SUBTITLE_SIZE_SMALL, + SUBTITLE_SIZE_NORMAL, + SUBTITLE_SIZE_LARGE, + SUBTITLE_SIZE_VERY_LARGE, + SUBTITLE_SIZE_HUGE, + + SUBTITLE_SIZE_NUM /* number of values in enum */ +} subtitle_size; + +#define FONTNAME_SIZE 100 + +typedef struct sputext_class_s { + spu_decoder_class_t class; + + subtitle_size subtitle_size; /* size of subtitles */ + int vertical_offset; + char font[FONTNAME_SIZE]; /* subtitle font */ +#ifdef HAVE_FT2 + char font_ft[FILENAME_MAX]; /* subtitle font */ + int use_font_ft; /* use Freetype */ +#endif + char *src_encoding; /* encoding of subtitle file */ + int use_unscaled; /* use unscaled OSD if possible */ + + xine_t *xine; + +} sputext_class_t; + + +typedef struct sputext_decoder_s { + spu_decoder_t spu_decoder; + + sputext_class_t *class; + xine_stream_t *stream; + + int ogm; + int lines; + char text[SUB_MAX_TEXT][SUB_BUFSIZE]; + + /* below 3 variables are the same from class. use to detect + * when something changes. + */ + subtitle_size subtitle_size; /* size of subtitles */ + int vertical_offset; + char font[FILENAME_MAX]; /* subtitle font */ + char *buf_encoding; /* encoding of subtitle buffer */ + + int width; /* frame width */ + int height; /* frame height */ + int font_size; + int line_height; + int started; + int finished; + + osd_renderer_t *renderer; + osd_object_t *osd; + + int64_t img_duration; + int64_t last_subtitle_end; /* no new subtitle before this vpts */ + int unscaled; /* use unscaled OSD */ + + int last_lines; /* number of lines of the previous subtitle */ +} sputext_decoder_t; + +static inline char *get_font (sputext_class_t *class) +{ +#ifdef HAVE_FT2 + return class->use_font_ft ? class->font_ft : class->font; +#else + return class->font; +#endif +} + +static void update_font_size (sputext_decoder_t *this, int force_update) { + static int sizes[SUBTITLE_SIZE_NUM] = { 16, 20, 24, 32, 48, 64 }; + + int y; + + if ((this->subtitle_size != this->class->subtitle_size) || + (this->vertical_offset != this->class->vertical_offset) || + force_update) { + + this->subtitle_size = this->class->subtitle_size; + this->vertical_offset = this->class->vertical_offset; + this->last_lines = 0; + + this->font_size = sizes[this->class->subtitle_size]; + + this->line_height = this->font_size + 10; + + y = this->height - (SUB_MAX_TEXT * this->line_height) - 5; + + if(((y - this->class->vertical_offset) >= 0) && ((y - this->class->vertical_offset) <= this->height)) + y -= this->class->vertical_offset; + + if( this->osd ) + this->renderer->free_object (this->osd); + + lprintf("new osd object, width %d, height %d*%d\n", this->width, SUB_MAX_TEXT, this->line_height); + this->osd = this->renderer->new_object (this->renderer, + this->width, + SUB_MAX_TEXT * this->line_height); + + this->renderer->set_font (this->osd, get_font (this->class), this->font_size); + this->renderer->set_position (this->osd, 0, y); + } +} + +static void update_output_size (sputext_decoder_t *this) { + int unscaled; + + unscaled = this->class->use_unscaled && + (this->stream->video_out->get_capabilities(this->stream->video_out) & + VO_CAP_UNSCALED_OVERLAY); + + if( unscaled != this->unscaled ) { + this->unscaled = unscaled; + this->width = 0; /* force update */ + } + + /* initialize decoder if needed */ + if( this->unscaled ) { + if( this->width != this->stream->video_out->get_property(this->stream->video_out, + VO_PROP_WINDOW_WIDTH) || + this->height != this->stream->video_out->get_property(this->stream->video_out, + VO_PROP_WINDOW_HEIGHT) || + !this->img_duration || !this->osd ) { + + int width = 0, height = 0; /* dummy */ + + this->stream->video_out->status(this->stream->video_out, NULL, + &width, &height, &this->img_duration ); + if( width && height ) { + + this->width = this->stream->video_out->get_property(this->stream->video_out, + VO_PROP_WINDOW_WIDTH); + this->height = this->stream->video_out->get_property(this->stream->video_out, + VO_PROP_WINDOW_HEIGHT); + + if(!this->osd || (this->width && this->height)) { + this->renderer = this->stream->osd_renderer; + + update_font_size (this, 1); + } + } + } + } else { + if( !this->width || !this->height || !this->img_duration || !this->osd ) { + + this->width = 0; + this->height = 0; + + this->stream->video_out->status(this->stream->video_out, NULL, + &this->width, &this->height, &this->img_duration ); + + if(!this->osd || ( this->width && this->height)) { + this->renderer = this->stream->osd_renderer; + + update_font_size (this, 1); + } + } + } +} + +static int parse_utf8_size(unsigned char *c) +{ + if ( c[0]<0x80 ) + return 1; + + if( c[1]==0 ) + return 1; + if ( (c[0]>=0xC2 && c[0]<=0xDF) && (c[1]>=0x80 && c[1]<=0xBF) ) + return 2; + + if( c[2]==0 ) + return 2; + else if ( c[0]==0xE0 && (c[1]>=0xA0 && c[1]<=0xBF) && (c[2]>=0x80 && c[1]<=0xBF) ) + return 3; + else if ( (c[0]>=0xE1 && c[0]<=0xEC) && (c[1]>=0x80 && c[1]<=0xBF) && (c[2]>=0x80 && c[1]<=0xBF) ) + return 3; + else if ( c[0]==0xED && (c[1]>=0x80 && c[1]<=0x9F) && (c[2]>=0x80 && c[1]<=0xBF) ) + return 3; + else if ( c[0]==0xEF && (c[1]>=0xA4 && c[1]<=0xBF) && (c[2]>=0x80 && c[1]<=0xBF) ) + return 3; + else + return 1; +} + +static int ogm_get_width(sputext_decoder_t *this, char* text) { + int i=0,width=0,w,dummy; + char letter[5]={0, 0, 0, 0, 0}; + int shift, isutf8 = 0; + char *encoding = (this->buf_encoding)?this->buf_encoding: + this->class->src_encoding; + if( strcmp(encoding, "utf-8") == 0 ) + isutf8 = 1; + + while (i<=strlen(text)) { + switch (text[i]) { + case '<': + if (!strncmp("", text+i, 3)) { + /*Do somethink to enable BOLD typeface*/ + i=i+3; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable BOLD typeface*/ + i=i+4; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to enable italics typeface*/ + i=i+3; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable italics typeface*/ + i=i+4; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable typing + fixme - no teststreams*/ + i=i+6; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to enable typing + fixme - no teststreams*/ + i=i+7; + break; + } +default: + if ( isutf8 ) + shift = parse_utf8_size(&text[i]); + else + shift = 1; + memcpy(letter,&text[i],shift); + letter[shift]=0; + + this->renderer->get_text_size(this->osd, letter, &w, &dummy); + width=width+w; + i+=shift; + } + } + + return width; +} + +static void ogm_render_line(sputext_decoder_t *this, int x, int y, char* text) { + int i=0,w,dummy; + char letter[5]={0, 0, 0, 0, 0}; + int shift, isutf8 = 0; + char *encoding = (this->buf_encoding)?this->buf_encoding: + this->class->src_encoding; + if( strcmp(encoding, "utf-8") == 0 ) + isutf8 = 1; + + while (i<=strlen(text)) { + switch (text[i]) { + case '<': + if (!strncmp("", text+i, 3)) { + /*Do somethink to enable BOLD typeface*/ + i=i+3; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable BOLD typeface*/ + i=i+4; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to enable italics typeface*/ + i=i+3; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable italics typeface*/ + i=i+4; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to disable typing + fixme - no teststreams*/ + i=i+6; + break; + } else if (!strncmp("", text+i, 3)) { + /*Do somethink to enable typing + fixme - no teststreams*/ + i=i+7; + break; + } + default: + if ( isutf8 ) + shift = parse_utf8_size(&text[i]); + else + shift = 1; + memcpy(letter,&text[i],shift); + letter[shift]=0; + + this->renderer->render_text(this->osd, x, y, letter, OSD_TEXT1); + this->renderer->get_text_size(this->osd, letter, &w, &dummy); + x=x+w; + i+=shift; + } + } +} + +static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t sub_end ) { + + int line, y; + int font_size; + char *font; + + _x_assert(this->renderer != NULL); + if ( ! this->renderer ) + return; + + update_font_size(this, 0); + + font = get_font (this->class); + if( strcmp(this->font, font) ) { + strncpy(this->font, font, FILENAME_MAX); + this->font[FILENAME_MAX - 1] = '\0'; + this->renderer->set_font (this->osd, font, this->font_size); + } + + font_size = this->font_size; + if (this->buf_encoding) + this->renderer->set_encoding(this->osd, this->buf_encoding); + else + this->renderer->set_encoding(this->osd, this->class->src_encoding); + + for (line = 0; line < this->lines; line++) /* first, check lenghts and word-wrap if needed */ + { + int w, h; + if( this->ogm ) + w = ogm_get_width( this, this->text[line]); + else + this->renderer->get_text_size( this->osd, this->text[line], &w, &h); + if( w > this->width ) { /* line is too long */ + int chunks=(int)(w/this->width)+(w%this->width?1:0); + if( this->lines+chunks <= SUB_MAX_TEXT && chunks>1 ) { /* try adding newlines while keeping existing ones */ + int a; + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,"Partial subtitle line splitting in %i chunks\n",chunks); + for(a=this->lines-1;a>=0;a--) { + if(a>line) /* lines after the too-long one */ + memcpy(this->text[a+chunks-1],this->text[a],SUB_BUFSIZE); + else if(a==line) { /* line to be splitted */ + int b,len=strlen(this->text[line]); + char *p=this->text[line]; + for(b=0;btext[line+b],p,SUB_BUFSIZE); + this->text[line+b][SUB_BUFSIZE - 1] = '\0'; + } else { + for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); + if(*c==' ') { + *c='\0'; + if(b) { /* we are reading something that has to be moved to another line */ + strncpy(this->text[line+b],p,SUB_BUFSIZE); + this->text[line+b][SUB_BUFSIZE - 1] = '\0'; + } + p=c+1; + } + } + } + } + } + this->lines+=chunks-1; + } else { /* regenerate all the lines to find something that better fits */ + char buf[SUB_BUFSIZE*SUB_MAX_TEXT]; + int a,w,h,chunks; + buf[0]='\0'; + for(a=0;alines;a++) { + if(a) { + int len=strlen(buf); + buf[len]=' '; + buf[len+1]='\0'; + } + strcat(buf,this->text[a]); + } + if( this->ogm ) + w = ogm_get_width( this, buf); + else + this->renderer->get_text_size( this->osd, buf, &w, &h); + chunks=(int)(w/this->width)+(w%this->width?1:0); + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Complete subtitle line splitting in %i chunks\n",chunks); + if(chunks<=SUB_MAX_TEXT) {/* if the length is over than SUB_MAX_TEXT*this->width nothing can be done */ + int b,len=strlen(buf); + char *p=buf; + for(b=0;btext[b],p,SUB_BUFSIZE); + this->text[b][SUB_BUFSIZE - 1] = '\0'; + } else { + for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); + if(*c==' ') { + *c='\0'; + strncpy(this->text[b],p,SUB_BUFSIZE); + this->text[b][SUB_BUFSIZE - 1] = '\0'; + p=c+1; + } + } + } + this->lines=chunks; + } else + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Subtitle too long to be splited\n"); + line=this->lines; + } + } + } + + font_size = this->font_size; + if (this->buf_encoding) + this->renderer->set_encoding(this->osd, this->buf_encoding); + else + this->renderer->set_encoding(this->osd, this->class->src_encoding); + + for (line = 0; line < this->lines; line++) /* first, check lenghts and word-wrap if needed */ + { + int w, h; + if( this->ogm ) + w = ogm_get_width( this, this->text[line]); + else + this->renderer->get_text_size( this->osd, this->text[line], &w, &h); + if( w > this->width ) { /* line is too long */ + int chunks=(int)(w/this->width)+(w%this->width?1:0); + if( this->lines+chunks <= SUB_MAX_TEXT && chunks>1 ) { /* try adding newlines while keeping existing ones */ + int a; + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,"Partial subtitle line splitting in %i chunks\n",chunks); + for(a=this->lines-1;a>=0;a--) { + if(a>line) /* lines after the too-long one */ + memcpy(this->text[a+chunks-1],this->text[a],SUB_BUFSIZE); + else if(a==line) { /* line to be splitted */ + int b,len=strlen(this->text[line]); + char *p=this->text[line]; + for(b=0;btext[line+b],p,SUB_BUFSIZE); + this->text[line+b][SUB_BUFSIZE - 1] = '\0'; + } else { + for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); + if(*c==' ') { + *c='\0'; + if(b) { /* we are reading something that has to be moved to another line */ + strncpy(this->text[line+b],p,SUB_BUFSIZE); + this->text[line+b][SUB_BUFSIZE - 1] = '\0'; + } + p=c+1; + } + } + } + } + } + this->lines+=chunks-1; + } else { /* regenerate all the lines to find something that better fits */ + char buf[SUB_BUFSIZE*SUB_MAX_TEXT]; + int a,w,h,chunks; + buf[0]='\0'; + for(a=0;alines;a++) { + if(a) { + int len=strlen(buf); + buf[len]=' '; + buf[len+1]='\0'; + } + strcat(buf,this->text[a]); + } + if( this->ogm ) + w = ogm_get_width( this, buf); + else + this->renderer->get_text_size( this->osd, buf, &w, &h); + chunks=(int)(w/this->width)+(w%this->width?1:0); + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Complete subtitle line splitting in %i chunks\n",chunks); + if(chunks<=SUB_MAX_TEXT) {/* if the length is over than SUB_MAX_TEXT*this->width nothing can be done */ + int b,len=strlen(buf); + char *p=buf; + for(b=0;btext[b],p,SUB_BUFSIZE); + this->text[b][SUB_BUFSIZE - 1] = '\0'; + } else { + for(c=p+(int)(len/chunks)+(len%chunks?1:0);*c!=' ' && c>p && c!='\0';c--); + if(*c==' ') { + *c='\0'; + strncpy(this->text[b],p,SUB_BUFSIZE); + this->text[b][SUB_BUFSIZE - 1] = '\0'; + p=c+1; + } + } + } + this->lines=chunks; + } else + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Subtitle too long to be splited\n"); + line=this->lines; + } + } + } + + if (this->last_lines) + this->renderer->filled_rect (this->osd, 0, this->line_height * (SUB_MAX_TEXT - this->last_lines), + this->width - 1, this->line_height * SUB_MAX_TEXT - 1, 0); + this->last_lines = this->lines; + y = (SUB_MAX_TEXT - this->lines) * this->line_height; + + for (line = 0; line < this->lines; line++) { + int w, h, x; + + while(1) { + if( this->ogm ) + w = ogm_get_width( this, this->text[line]); + else + this->renderer->get_text_size( this->osd, this->text[line], + &w, &h); + x = (this->width - w) / 2; + + if( w > this->width && font_size > 16 ) { + font_size -= 4; + this->renderer->set_font (this->osd, get_font (this->class), font_size); + } else { + break; + } + } + + if( this->ogm ) { + ogm_render_line(this, x, y + line*this->line_height, this->text[line]); + } else { + this->renderer->render_text (this->osd, x, y + line * this->line_height, + this->text[line], OSD_TEXT1); + } + } + + if( font_size != this->font_size ) + this->renderer->set_font (this->osd, get_font (this->class), this->font_size); + + if( this->last_subtitle_end && sub_start < this->last_subtitle_end ) { + sub_start = this->last_subtitle_end; + } + this->last_subtitle_end = sub_end; + + this->renderer->set_text_palette (this->osd, -1, OSD_TEXT1); + + if (this->unscaled) + this->renderer->show_unscaled (this->osd, sub_start); + else + this->renderer->show (this->osd, sub_start); + + this->renderer->hide (this->osd, sub_end); + + lprintf ("scheduling subtitle >%s< at %"PRId64" until %"PRId64", current time is %"PRId64"\n", + this->text[0], sub_start, sub_end, + this->stream->xine->clock->get_current_time (this->stream->xine->clock)); +} + + +static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { + + sputext_decoder_t *this = (sputext_decoder_t *) this_gen; + int uses_time; + int32_t start, end, diff; + int64_t start_vpts, end_vpts; + int64_t spu_offset; + int i; + uint32_t *val; + char *str; + extra_info_t extra_info; + int master_status, slave_status; + int vo_discard; + + /* filter unwanted streams */ + if (buf->decoder_flags & BUF_FLAG_HEADER) { + return; + } + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + if ((this->stream->spu_channel & 0x1f) != (buf->type & 0x1f)) + return; + + if ( (buf->decoder_flags & BUF_FLAG_SPECIAL) && + (buf->decoder_info[1] == BUF_SPECIAL_CHARSET_ENCODING) ) + this->buf_encoding = buf->decoder_info_ptr[2]; + else + this->buf_encoding = NULL; + + if( (buf->type & 0xFFFF0000) == BUF_SPU_OGM ) { + + this->ogm = 1; + uses_time = 1; + val = (uint32_t * )buf->content; + start = *val++; + end = *val++; + str = (char *)val; + + if (!*str) return; + /* Empty ogm packets (as created by ogmmux) clears out old messages. We already respect the end time. */ + + this->lines = 0; + + i = 0; + while (*str && (this->lines < SUB_MAX_TEXT) && (i < SUB_BUFSIZE)) { + if (*str == '\r' || *str == '\n') { + if (i) { + this->text[ this->lines ][i] = 0; + this->lines++; + i = 0; + } + } else { + this->text[ this->lines ][i] = *str; + if (i < SUB_BUFSIZE-1) + i++; + } + str++; + } + if (i == SUB_BUFSIZE) + i--; + + if (i) { + this->text[ this->lines ][i] = 0; + this->lines++; + } + + } else { + + this->ogm = 0; + val = (uint32_t * )buf->content; + + this->lines = *val++; + uses_time = *val++; + start = *val++; + end = *val++; + str = (char *)val; + for (i = 0; i < this->lines; i++, str += strlen(str) + 1) { + strncpy( this->text[i], str, SUB_BUFSIZE - 1); + this->text[i][SUB_BUFSIZE - 1] = '\0'; + } + + } + + xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, + "libsputext: decoder data [%s]\n", this->text[0]); + xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, + "libsputext: mode %d timing %d->%d\n", uses_time, start, end); + + if( end <= start ) { + xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, + "libsputext: discarding subtitle with invalid timing\n"); + return; + } + + spu_offset = this->stream->master->metronom->get_option (this->stream->master->metronom, + METRONOM_SPU_OFFSET); + if( uses_time ) { + start += (spu_offset / 90); + end += (spu_offset / 90); + } else { + if( this->osd && this->img_duration ) { + start += spu_offset / this->img_duration; + end += spu_offset / this->img_duration; + } + } + + while( !this->finished ) { + + master_status = xine_get_status (this->stream->master); + slave_status = xine_get_status (this->stream); + vo_discard = this->stream->video_out->get_property(this->stream->video_out, + VO_PROP_DISCARD_FRAMES); + + _x_get_current_info (this->stream->master, &extra_info, sizeof(extra_info) ); + + lprintf("master: %d slave: %d input_normpos: %d vo_discard: %d\n", + master_status, slave_status, extra_info.input_normpos, vo_discard); + + if( !this->started && (master_status == XINE_STATUS_PLAY && + slave_status == XINE_STATUS_PLAY && + extra_info.input_normpos) ) { + lprintf("started\n"); + + this->width = this->height = 0; + this->started = 1; + + update_output_size( this ); + } + + if( this->started ) { + + if( master_status != XINE_STATUS_PLAY || + slave_status != XINE_STATUS_PLAY || + vo_discard ) { + lprintf("finished\n"); + + this->width = this->height = 0; + this->finished = 1; + return; + } + + if( this->osd ) { + + /* try to use frame number mode */ + if( !uses_time && extra_info.frame_number ) { + + diff = end - extra_info.frame_number; + + /* discard old subtitles */ + if( diff < 0 ) { + xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, + "libsputext: discarding old subtitle\n"); + return; + } + + diff = start - extra_info.frame_number; + + start_vpts = extra_info.vpts + diff * this->img_duration; + end_vpts = start_vpts + (end-start) * this->img_duration; + + } else { + + if( !uses_time ) { + start = start * this->img_duration / 90; + end = end * this->img_duration / 90; + uses_time = 1; + } + + diff = end - extra_info.input_time; + + /* discard old subtitles */ + if( diff < 0 ) { + xprintf(this->class->xine, XINE_VERBOSITY_DEBUG, + "libsputext: discarding old subtitle\n"); + return; + } + + diff = start - extra_info.input_time; + + start_vpts = extra_info.vpts + diff * 90; + end_vpts = start_vpts + (end-start) * 90; + } + + _x_spu_decoder_sleep(this->stream, start_vpts); + update_output_size( this ); + draw_subtitle(this, start_vpts, end_vpts); + + return; + } + } + + if (_x_spu_decoder_sleep(this->stream, 0)) + xine_usec_sleep (50000); + else + return; + } +} + + +static void spudec_reset (spu_decoder_t *this_gen) { + sputext_decoder_t *this = (sputext_decoder_t *) this_gen; + + lprintf("i guess we just seeked\n"); + this->width = this->height = 0; + this->started = this->finished = 0; + this->last_subtitle_end = 0; +} + +static void spudec_discontinuity (spu_decoder_t *this_gen) { + /* sputext_decoder_t *this = (sputext_decoder_t *) this_gen; */ + +} + +static void spudec_dispose (spu_decoder_t *this_gen) { + sputext_decoder_t *this = (sputext_decoder_t *) this_gen; + + if (this->osd) { + this->renderer->free_object (this->osd); + this->osd = NULL; + } + free(this); +} + +static void update_vertical_offset(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + class->vertical_offset = entry->num_value; +} + +static void update_osd_font(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + strncpy(class->font, entry->str_value, FONTNAME_SIZE); + class->font[FONTNAME_SIZE - 1] = '\0'; + + xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_font = %s\n", class->font ); +} + +#ifdef HAVE_FT2 +static void update_osd_font_ft(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + strncpy(class->font_ft, entry->str_value, FILENAME_MAX); + class->font_ft[FILENAME_MAX - 1] = '\0'; + + xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_font_ft = %s\n", class->font_ft); +} + +static void update_osd_use_font_ft(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + class->use_font_ft = entry->num_value; + + xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_use_font_ft = %d\n", class->use_font_ft); +} +#endif + +static void update_subtitle_size(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + class->subtitle_size = entry->num_value; +} + +static void update_use_unscaled(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + class->use_unscaled = entry->num_value; +} + +static spu_decoder_t *sputext_class_open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { + + sputext_class_t *class = (sputext_class_t *)class_gen; + sputext_decoder_t *this ; + + this = (sputext_decoder_t *) xine_xmalloc (sizeof (sputext_decoder_t)); + + this->spu_decoder.decode_data = spudec_decode_data; + this->spu_decoder.reset = spudec_reset; + this->spu_decoder.discontinuity = spudec_discontinuity; + this->spu_decoder.get_interact_info = NULL; + this->spu_decoder.set_button = NULL; + this->spu_decoder.dispose = spudec_dispose; + + this->class = class; + this->stream = stream; + + return (spu_decoder_t *) this; +} + +static void sputext_class_dispose (spu_decoder_class_t *class_gen) { + sputext_class_t *this = (sputext_class_t *)class_gen; + + this->xine->config->unregister_callback(this->xine->config, + "subtitles.separate.src_encoding"); + this->xine->config->unregister_callback(this->xine->config, + "subtitles.separate.subtitle_size"); + this->xine->config->unregister_callback(this->xine->config, + "subtitles.separate.vertical_offset"); + this->xine->config->unregister_callback(this->xine->config, + "subtitles.separate.use_unscaled_osd"); + free (this); +} + +static char *sputext_class_get_identifier (spu_decoder_class_t *this) { + return "sputext"; +} + +static char *sputext_class_get_description (spu_decoder_class_t *this) { + return "external subtitle decoder plugin"; +} + +static void update_src_encoding(void *class_gen, xine_cfg_entry_t *entry) +{ + sputext_class_t *class = (sputext_class_t *)class_gen; + + class->src_encoding = entry->str_value; + xprintf(class->xine, XINE_VERBOSITY_DEBUG, "libsputext: spu_src_encoding = %s\n", class->src_encoding ); +} + +static void *init_spu_decoder_plugin (xine_t *xine, void *data) { + + static const char *subtitle_size_strings[] = { + "tiny", "small", "normal", "large", "very large", "huge", NULL + }; + sputext_class_t *this ; + + lprintf("init class\n"); + + this = (sputext_class_t *) xine_xmalloc (sizeof (sputext_class_t)); + + this->class.open_plugin = sputext_class_open_plugin; + this->class.get_identifier = sputext_class_get_identifier; + this->class.get_description = sputext_class_get_description; + this->class.dispose = sputext_class_dispose; + + this->xine = xine; + + this->subtitle_size = xine->config->register_enum(xine->config, + "subtitles.separate.subtitle_size", + 1, + subtitle_size_strings, + _("subtitle size"), + _("You can adjust the subtitle size here. The setting will " + "be evaluated relative to the window size."), + 0, update_subtitle_size, this); + this->vertical_offset = xine->config->register_num(xine->config, + "subtitles.separate.vertical_offset", + 0, + _("subtitle vertical offset"), + _("You can adjust the vertical position of the subtitle. " + "The setting will be evaluated relative to the window size."), + 0, update_vertical_offset, this); + strncpy(this->font, xine->config->register_string(xine->config, + "subtitles.separate.font", + "sans", + _("font for subtitles"), + _("A font from the xine font directory to be used for the " + "subtitle text."), + 10, update_osd_font, this), FONTNAME_SIZE); + this->font[FONTNAME_SIZE - 1] = '\0'; +#ifdef HAVE_FT2 + strncpy(this->font_ft, xine->config->register_filename(xine->config, + "subtitles.separate.font_freetype", + "", XINE_CONFIG_STRING_IS_FILENAME, + _("font for subtitles"), + _("An outline font file (e.g. a .ttf) to be used for the subtitle text."), + 10, update_osd_font_ft, this), FILENAME_MAX); + this->font_ft[FILENAME_MAX - 1] = '\0'; + this->use_font_ft = xine->config->register_bool(xine->config, + "subtitles.separate.font_use_freetype", + 0, + _("whether to use a freetype font"), + NULL, + 10, update_osd_use_font_ft, this); +#endif + this->src_encoding = xine->config->register_string(xine->config, + "subtitles.separate.src_encoding", + xine_guess_spu_encoding(), + _("encoding of the subtitles"), + _("The encoding of the subtitle text in the stream. This setting " + "is used to render non-ASCII characters correctly. If non-ASCII " + "characters are not displayed as you expect, ask the " + "creator of the subtitles what encoding was used."), + 10, update_src_encoding, this); + this->use_unscaled = xine->config->register_bool(xine->config, + "subtitles.separate.use_unscaled_osd", + 1, + _("use unscaled OSD if possible"), + _("The unscaled OSD will be rendered independently of the video " + "frame and will always be sharp, even if the video is magnified. " + "This will look better, but does not work with all graphics " + "hardware. The alternative is the scaled OSD, which will become " + "blurry, if you enlarge a low resolution video to fullscreen, but " + "it works with all graphics cards."), + 10, update_use_unscaled, this); + + return &this->class; +} + + +/* plugin catalog information */ +static uint32_t supported_types[] = { BUF_SPU_TEXT, BUF_SPU_OGM, 0 }; + +static const decoder_info_t spudec_info = { + supported_types, /* supported types */ + 1 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_SPU_DECODER | PLUGIN_MUST_PRELOAD, 16, "sputext", XINE_VERSION_CODE, &spudec_info, &init_spu_decoder_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3 From a4421450c27c75598774d5f330a765eb74f34556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 4 Apr 2007 22:55:23 +0200 Subject: Fix xine_encoder.c presence in EXTRA_DIST. --- src/libffmpeg/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am index 1efc77327..19ea72b5e 100644 --- a/src/libffmpeg/Makefile.am +++ b/src/libffmpeg/Makefile.am @@ -16,7 +16,7 @@ endif DISTCLEANFILES = ffmpeg_config.h # this must always be included, even if the current machine has no DXR3... -EXTRA_DIST = xine_encoder.c diff_to_ffmpeg_cvs.txt +EXTRA_DIST = ffmpeg_encoder.c diff_to_ffmpeg_cvs.txt INTERNAL_DOCS = diff_to_ffmpeg_cvs.txt -- cgit v1.2.3 From 66f1aca41a4ff7668e5c21f59c3b2170d3d265e7 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 13:07:13 +0200 Subject: Fixed current audio sync, delay was always 0. Checked snd_pcm_delay return code, and don't trust negative values. --- src/audio_out/audio_alsa_out.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/audio_out/audio_alsa_out.c b/src/audio_out/audio_alsa_out.c index 3651d21da..f176b7594 100644 --- a/src/audio_out/audio_alsa_out.c +++ b/src/audio_out/audio_alsa_out.c @@ -663,15 +663,7 @@ static int ao_alsa_delay (ao_driver_t *this_gen) { struct timeval now; printf("audio_alsa_out:delay:ENTERED\n"); #endif - err=snd_pcm_delay( this->audio_fd, &delay ); - - int state = snd_pcm_state(this->audio_fd); - - /* check for idle states, which need to be handled as delay=0 */ - if(state == SND_PCM_STATE_PREPARED || state == SND_PCM_STATE_PAUSED || - state == SND_PCM_STATE_OPEN || SND_PCM_STATE_XRUN) { - return 0; - } + err = snd_pcm_delay( this->audio_fd, &delay ); #ifdef LOG_DEBUG printf("audio_alsa_out:delay:delay all=%ld err=%d\n",delay, err); @@ -679,8 +671,11 @@ static int ao_alsa_delay (ao_driver_t *this_gen) { printf("audio_alsa_out:delay: Time = %ld.%ld\n", now.tv_sec, now.tv_usec); printf("audio_alsa_out:delay:FINISHED\n"); #endif - return delay; + if (err || (delay < 0)) + delay = 0; + + return delay; } #if 0 -- cgit v1.2.3 From d4c9af94f21cd575bd57da36d489d37812a5610e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 6 Apr 2007 15:31:01 +0200 Subject: Use xineplug_LTLIBRARIES wherever possible. --- src/audio_out/Makefile.am | 4 +--- src/dxr3/Makefile.am | 4 +--- src/input/Makefile.am | 4 +--- src/input/vcd/Makefile.am | 4 +--- src/libspucc/Makefile.am | 4 +--- src/libspudvb/Makefile.am | 4 +--- src/libw32dll/Makefile.am | 4 +--- 7 files changed, 7 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/audio_out/Makefile.am b/src/audio_out/Makefile.am index d52f700f3..1329b0f62 100644 --- a/src/audio_out/Makefile.am +++ b/src/audio_out/Makefile.am @@ -4,8 +4,6 @@ AM_CPPFLAGS = -DXINE_COMPILE EXTRA_DIST = audio_irixal_out.c -libdir = $(XINE_PLUGINDIR) - if HAVE_OSS oss_module = xineplug_ao_out_oss.la endif @@ -57,7 +55,7 @@ endif # all xine audio out plugins should be named like the # scheme "xineplug_ao_out_" # -lib_LTLIBRARIES = xineplug_ao_out_none.la xineplug_ao_out_file.la \ +xineplug_LTLIBRARIES = xineplug_ao_out_none.la xineplug_ao_out_file.la \ $(oss_module) \ $(alsa_module) \ $(sun_module) \ diff --git a/src/dxr3/Makefile.am b/src/dxr3/Makefile.am index 8bf9c9427..5f413f804 100644 --- a/src/dxr3/Makefile.am +++ b/src/dxr3/Makefile.am @@ -2,8 +2,6 @@ include $(top_srcdir)/misc/Makefile.common AM_CFLAGS = $(X_CFLAGS) $(LIBFAME_CFLAGS) -libdir = $(XINE_PLUGINDIR) - if HAVE_DXR3 dxr3_modules = xineplug_decode_dxr3_video.la \ xineplug_decode_dxr3_spu.la \ @@ -19,7 +17,7 @@ if HAVE_LIBRTE link_rte = -lrte endif -lib_LTLIBRARIES = $(dxr3_modules) +xineplug_LTLIBRARIES = $(dxr3_modules) xineplug_decode_dxr3_video_la_SOURCES = dxr3_decode_video.c xineplug_decode_dxr3_video_la_LIBADD = $(XINE_LIB) diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 68adf84be..a2a1ea3a4 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -8,8 +8,6 @@ else SUBDIRS = vcd dvb libreal librtsp libdvdnav endif -libdir = $(XINE_PLUGINDIR) - ## # IMPORTANT: # --------- @@ -52,7 +50,7 @@ endif AM_CFLAGS = -D_LARGEFILE64_SOURCE $(GNOME_VFS_CFLAGS) $(ALSA_CFLAGS) $(DVD_CFLAGS) -lib_LTLIBRARIES = \ +xineplug_LTLIBRARIES = \ xineplug_inp_file.la \ xineplug_inp_http.la \ $(in_dvd) \ diff --git a/src/input/vcd/Makefile.am b/src/input/vcd/Makefile.am index 98903aac8..16eece779 100644 --- a/src/input/vcd/Makefile.am +++ b/src/input/vcd/Makefile.am @@ -2,14 +2,12 @@ include $(top_srcdir)/misc/Makefile.common SUBDIRS = libcdio libvcd -libdir = $(XINE_PLUGINDIR) - vcd_SRCS = xineplug_inp_vcd.c vcdplayer.c vcdio.c xine-extra.c EXTRA_DIST = $(vcd_SRCS) if ENABLE_VCD -lib_LTLIBRARIES = xineplug_inp_vcd.la +xineplug_LTLIBRARIES = xineplug_inp_vcd.la AM_CFLAGS = $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS) diff --git a/src/libspucc/Makefile.am b/src/libspucc/Makefile.am index ec12c1bc7..aefe4d7c1 100644 --- a/src/libspucc/Makefile.am +++ b/src/libspucc/Makefile.am @@ -1,8 +1,6 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_spucc.la +xineplug_LTLIBRARIES = xineplug_decode_spucc.la xineplug_decode_spucc_la_SOURCES = cc_decoder.c xine_cc_decoder.c xineplug_decode_spucc_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -fno-strict-aliasing diff --git a/src/libspudvb/Makefile.am b/src/libspudvb/Makefile.am index b4ae9befe..e385e5553 100644 --- a/src/libspudvb/Makefile.am +++ b/src/libspudvb/Makefile.am @@ -1,8 +1,6 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = xineplug_decode_spudvb.la +xineplug_LTLIBRARIES = xineplug_decode_spudvb.la xineplug_decode_spudvb_la_SOURCES = xine_spudvb_decoder.c xineplug_decode_spudvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) diff --git a/src/libw32dll/Makefile.am b/src/libw32dll/Makefile.am index 46027d0f1..358eea40a 100644 --- a/src/libw32dll/Makefile.am +++ b/src/libw32dll/Makefile.am @@ -9,9 +9,7 @@ w32dll_codec = xineplug_decode_w32dll.la qt_codec = xineplug_decode_qt.la endif -libdir = $(XINE_PLUGINDIR) - -lib_LTLIBRARIES = $(w32dll_codec) $(qt_codec) +xineplug_LTLIBRARIES = $(w32dll_codec) $(qt_codec) EXTRA_DIST = common.c -- cgit v1.2.3 From e7b343f647fa5c44551946b39afdeebe0812c8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 6 Apr 2007 16:17:04 +0200 Subject: Define a xinepostdir directory to point to the post-plugins path. Together with this, define a xinepost_LTLIBRARIES class that is used to install the post-plugins in the correct directory. Also add the rule to remove them. --- src/post/audio/Makefile.am | 4 +--- src/post/deinterlace/Makefile.am | 4 +--- src/post/deinterlace/plugins/Makefile.am | 2 -- src/post/goom/Makefile.am | 4 +--- src/post/mosaico/Makefile.am | 4 +--- src/post/planar/Makefile.am | 4 +--- src/post/visualizations/Makefile.am | 4 +--- 7 files changed, 6 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/post/audio/Makefile.am b/src/post/audio/Makefile.am index 9cb93dd5a..f4018a780 100644 --- a/src/post/audio/Makefile.am +++ b/src/post/audio/Makefile.am @@ -2,9 +2,7 @@ include $(top_srcdir)/misc/Makefile.common noinst_HEADERS = dsp.h filter.h window.h audio_filters.h -libdir = $(XINE_PLUGINDIR)/post - -lib_LTLIBRARIES = xineplug_post_audio_filters.la +xinepost_LTLIBRARIES = xineplug_post_audio_filters.la xineplug_post_audio_filters_la_SOURCES = \ upmix.c upmix_mono.c filter.c window.c stretch.c volnorm.c audio_filters.c diff --git a/src/post/deinterlace/Makefile.am b/src/post/deinterlace/Makefile.am index 0914e114a..d2d1d5c10 100644 --- a/src/post/deinterlace/Makefile.am +++ b/src/post/deinterlace/Makefile.am @@ -4,9 +4,7 @@ SUBDIRS = plugins EXTRA_DIST = -libdir = $(XINE_PLUGINDIR)/post - -lib_LTLIBRARIES = xineplug_post_tvtime.la +xinepost_LTLIBRARIES = xineplug_post_tvtime.la xineplug_post_tvtime_la_SOURCES = xine_plugin.c \ deinterlace.c pulldown.c speedy.c tvtime.c diff --git a/src/post/deinterlace/plugins/Makefile.am b/src/post/deinterlace/plugins/Makefile.am index e6e785211..17d170127 100644 --- a/src/post/deinterlace/plugins/Makefile.am +++ b/src/post/deinterlace/plugins/Makefile.am @@ -32,8 +32,6 @@ EXTRA_DIST = greedy2frame_template.c greedyh.asm \ AM_CFLAGS = -I$(top_srcdir)/src/post/deinterlace \ -I$(top_srcdir)/src/libffmpeg/libavcodec/libpostproc -libdir = $(XINE_PLUGINDIR)/post - noinst_LTLIBRARIES = libdeinterlaceplugins.la libdeinterlaceplugins_la_SOURCES = \ diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am index 4aeda8f04..e6bae3374 100644 --- a/src/post/goom/Makefile.am +++ b/src/post/goom/Makefile.am @@ -1,7 +1,5 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR)/post - EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s diff_against_release.patch \ gfontrle.c mathtools.c @@ -10,7 +8,7 @@ EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s diff_against_releas #CFLAGS = `echo @CFLAGS@ | sed -e 's/-fomit-frame-pointer//g;s/-Os/-O2/g'` CFLAGS = `echo @CFLAGS@ | sed -e 's/-Os/-O2/g'` -lib_LTLIBRARIES = xineplug_post_goom.la +xinepost_LTLIBRARIES = xineplug_post_goom.la ## doesn't work #if PPC_ARCH diff --git a/src/post/mosaico/Makefile.am b/src/post/mosaico/Makefile.am index f5497b1af..c18b4e19c 100644 --- a/src/post/mosaico/Makefile.am +++ b/src/post/mosaico/Makefile.am @@ -1,8 +1,6 @@ include $(top_srcdir)/misc/Makefile.common -libdir = $(XINE_PLUGINDIR)/post - -lib_LTLIBRARIES = xineplug_post_mosaico.la xineplug_post_switch.la +xinepost_LTLIBRARIES = xineplug_post_mosaico.la xineplug_post_switch.la xineplug_post_mosaico_la_SOURCES = mosaico.c xineplug_post_mosaico_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) diff --git a/src/post/planar/Makefile.am b/src/post/planar/Makefile.am index 2e60671b5..5fc425cdf 100644 --- a/src/post/planar/Makefile.am +++ b/src/post/planar/Makefile.am @@ -15,9 +15,7 @@ endif # work, but at least it compiles. AM_CFLAGS = $(ff_cflags) -fomit-frame-pointer -libdir = $(XINE_PLUGINDIR)/post - -lib_LTLIBRARIES = xineplug_post_planar.la +xinepost_LTLIBRARIES = xineplug_post_planar.la xineplug_post_planar_la_SOURCES = planar.c invert.c expand.c fill.c boxblur.c \ denoise3d.c eq.c eq2.c unsharp.c pp.c noise.c diff --git a/src/post/visualizations/Makefile.am b/src/post/visualizations/Makefile.am index dc7679103..f42598d9c 100644 --- a/src/post/visualizations/Makefile.am +++ b/src/post/visualizations/Makefile.am @@ -2,9 +2,7 @@ include $(top_srcdir)/misc/Makefile.common EXTRA_DIST = fooviz.c -libdir = $(XINE_PLUGINDIR)/post - -lib_LTLIBRARIES = xineplug_post_visualizations.la +xinepost_LTLIBRARIES = xineplug_post_visualizations.la xineplug_post_visualizations_la_SOURCES = \ visualizations.c fft.c fftscope.c oscope.c fftgraph.c -- cgit v1.2.3 From 8d13033d6c84109fff3d2788d9bb844462ad6b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 6 Apr 2007 16:18:25 +0200 Subject: Similarly, add a vidix_LTLIBRARIES class to install the vidix drivers in the correct location. --- src/video_out/vidix/drivers/Makefile.am | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/video_out/vidix/drivers/Makefile.am b/src/video_out/vidix/drivers/Makefile.am index 3c0369af7..f438dde36 100644 --- a/src/video_out/vidix/drivers/Makefile.am +++ b/src/video_out/vidix/drivers/Makefile.am @@ -2,8 +2,6 @@ include $(top_srcdir)/misc/Makefile.common EXTRA_DIST = genfb_vid.c -libdir = $(XINE_PLUGINDIR)/vidix - if HAVE_VIDIX vidix_drivers = \ mach64_vid.la \ @@ -20,7 +18,7 @@ vidix_drivers = \ savage_vid.la endif -lib_LTLIBRARIES = $(vidix_drivers) +vidix_LTLIBRARIES = $(vidix_drivers) radeon_vid_la_SOURCES = radeon_vid.c radeon_vid_la_LDFLAGS = -avoid-version -module -lm -- cgit v1.2.3 From 0a725e9e1bceb83c24c0e2455d640fd616be74a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 6 Apr 2007 16:28:15 +0200 Subject: Remove a redundant comment. --- src/audio_out/Makefile.am | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') diff --git a/src/audio_out/Makefile.am b/src/audio_out/Makefile.am index 1329b0f62..20a4e708b 100644 --- a/src/audio_out/Makefile.am +++ b/src/audio_out/Makefile.am @@ -68,14 +68,6 @@ xineplug_LTLIBRARIES = xineplug_ao_out_none.la xineplug_ao_out_file.la \ $(fusionsound_module) \ $(jack_module) -#lib_LTLIBRARIES = \ -# $(alsa_module) \ -# $(arts_module) \ -# $(esd_module) \ -# $(irixal_module) \ -# $(oss_module) \ -# $(sun_module) - xineplug_ao_out_none_la_SOURCES = audio_none_out.c xineplug_ao_out_none_la_LIBADD = $(XINE_LIB) xineplug_ao_out_none_la_CFLAGS = $(VISIBILITY_FLAG) -- cgit v1.2.3