From fbde8d328d2b82e9f95ea5a181737df7bf33e101 Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Thu, 2 Jan 2003 06:10:49 +0000 Subject: writing demuxers like they're going out of style or something...added demuxers for Westwood Studios AUD, Playstation STR, and TechnoTrend PVA CVS patchset: 3749 CVS date: 2003/01/02 06:10:49 --- src/demuxers/Makefile.am | 19 ++- src/demuxers/demux_aud.c | 411 ++++++++++++++++++++++++++++++++++++++++++++++ src/demuxers/demux_pva.c | 416 ++++++++++++++++++++++++++++++++++++++++++++++ src/demuxers/demux_str.c | 420 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1264 insertions(+), 2 deletions(-) create mode 100644 src/demuxers/demux_aud.c create mode 100644 src/demuxers/demux_pva.c create mode 100644 src/demuxers/demux_str.c (limited to 'src') diff --git a/src/demuxers/Makefile.am b/src/demuxers/Makefile.am index 00472e1a9..64754e3da 100644 --- a/src/demuxers/Makefile.am +++ b/src/demuxers/Makefile.am @@ -50,7 +50,10 @@ lib_LTLIBRARIES = $(ogg_module) $(asf_module) $(mng_module) \ xineplug_dmx_realaudio.la \ xineplug_dmx_eawve.la \ xineplug_dmx_rawdv.la \ - xineplug_dmx_ipmovie.la + xineplug_dmx_ipmovie.la \ + xineplug_dmx_str.la \ + xineplug_dmx_pva.la \ + xineplug_dmx_aud.la xineplug_dmx_ogg_la_SOURCES = demux_ogg.c xineplug_dmx_ogg_la_LIBADD = $(OGG_LIBS) $(VORBIS_LIBS) $(XINELIB) @@ -165,9 +168,21 @@ xineplug_dmx_mng_la_LIBADD = $(XINELIB) $(ZLIB_LIBS) $(MNG_LIBS) xineplug_dmx_mng_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ xineplug_dmx_ipmovie_la_SOURCES = demux_ipmovie.c -xineplug_dmx_ipmovie_la_LIBADD = $(XINELIB) $(ZLIB_LIBS) $(MNG_LIBS) +xineplug_dmx_ipmovie_la_LIBADD = $(XINELIB) xineplug_dmx_ipmovie_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ +xineplug_dmx_str_la_SOURCES = demux_str.c +xineplug_dmx_str_la_LIBADD = $(XINELIB) +xineplug_dmx_str_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ + +xineplug_dmx_pva_la_SOURCES = demux_pva.c +xineplug_dmx_pva_la_LIBADD = $(XINELIB) +xineplug_dmx_pva_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ + +xineplug_dmx_aud_la_SOURCES = demux_aud.c +xineplug_dmx_aud_la_LIBADD = $(XINELIB) +xineplug_dmx_aud_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ + include_HEADERS = demux.h noinst_HEADERS = asfheader.h qtpalette.h diff --git a/src/demuxers/demux_aud.c b/src/demuxers/demux_aud.c new file mode 100644 index 000000000..3abb391d5 --- /dev/null +++ b/src/demuxers/demux_aud.c @@ -0,0 +1,411 @@ +/* + * Copyright (C) 2000-2002 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 + * + * Westwood Studios AUD File Demuxer by Mike Melanson (melanson@pcisys.net) + * For more information regarding the AUD file format, refer to: + * http://www.geocities.com/SiliconValley/8682/aud3.txt + * + * Implementation note: There is no definite file signature in this format. + * This demuxer uses a probabilistic strategy for content detection. This + * entails performing sanity checks on certain header values in order to + * qualify a file. Refer to open_aud_file() for the precise parameters. + * + * Implementation note #2: The IMA ADPCM data stored in this file format + * does not encode any initialization information; decoding parameters are + * initialized to 0 at the start of the file and maintained throughout the + * data. This makes seeking conceptually impossible. Upshot: Random + * seeking is not supported. + * + * $Id: demux_aud.c,v 1.1 2003/01/02 06:10:49 tmmm Exp $ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include "xine_internal.h" +#include "xineutils.h" +#include "compat.h" +#include "demux.h" +#include "bswap.h" + +#define AUD_HEADER_SIZE 12 +#define AUD_CHUNK_PREAMBLE_SIZE 8 + +typedef struct { + + demux_plugin_t demux_plugin; + + xine_stream_t *stream; + + config_values_t *config; + + fifo_buffer_t *video_fifo; + fifo_buffer_t *audio_fifo; + + input_plugin_t *input; + + pthread_t thread; + int thread_running; + pthread_mutex_t mutex; + int send_end_buffers; + + off_t data_start; + off_t data_size; + int status; + + int audio_samplerate; + int audio_channels; + int audio_bits; + int audio_type; + int64_t audio_frame_counter; + + char last_mrl[1024]; + +} demux_aud_t; + +typedef struct { + + demux_class_t demux_class; + + /* class-wide, global variables here */ + + xine_t *xine; + config_values_t *config; +} demux_aud_class_t; + + +/* returns 1 if the AUD file was opened successfully, 0 otherwise */ +static int open_aud_file(demux_aud_t *this) { + + unsigned char header[AUD_HEADER_SIZE]; + + this->input->seek(this->input, 0, SEEK_SET); + if (this->input->read(this->input, header, AUD_HEADER_SIZE) != + AUD_HEADER_SIZE) + return 0; + + /* Probabilistic content detection strategy: There is no file signature + * so perform sanity checks on various header parameters: + * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers + * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers + * There is a total of 24 bits. The number space contains 2^24 = + * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations + * of numbers. There is a 80002/16777216 = 0.48% chance of a false + * positive. + */ + this->audio_samplerate = LE_16(&header[0]); + if ((this->audio_samplerate < 8000) || (this->audio_samplerate > 48000)) + return 0; + + if (header[11] == 1) + this->audio_type = BUF_AUDIO_WESTWOOD; + else if (header[11] == 99) + this->audio_type = BUF_AUDIO_VQA_IMA; + else + return 0; + + /* flag 0 indicates stereo */ + this->audio_channels = (header[10] & 0x1) + 1; + /* flag 1 indicates 16 bit audio */ + this->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8; + + this->data_start = AUD_HEADER_SIZE; + this->data_size = this->input->get_length(this->input) - this->data_start; + this->audio_frame_counter = 0; + + return 1; +} + +static int demux_aud_send_chunk(demux_plugin_t *this_gen) { + + demux_aud_t *this = (demux_aud_t *) this_gen; + unsigned char chunk_preamble[AUD_CHUNK_PREAMBLE_SIZE]; + unsigned int chunk_size; + off_t current_file_pos; + int64_t audio_pts; + buf_element_t *buf; + + if (this->input->read(this->input, chunk_preamble, AUD_CHUNK_PREAMBLE_SIZE) != + AUD_CHUNK_PREAMBLE_SIZE) { + this->status = DEMUX_FINISHED; + return this->status; + } + + /* validate the chunk */ + if (LE_32(&chunk_preamble[4]) != 0x0000DEAF) { + this->status = DEMUX_FINISHED; + return this->status; + } + + chunk_size = LE_16(&chunk_preamble[0]); + + current_file_pos = this->input->get_current_pos(this->input) - + this->data_start; + + /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ + this->audio_frame_counter += (chunk_size * 2) / this->audio_channels; + audio_pts = this->audio_frame_counter; + audio_pts *= 90000; + audio_pts /= this->audio_samplerate; + + while (chunk_size) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = this->audio_type; + buf->extra_info->input_pos = current_file_pos; + buf->extra_info->input_length = this->data_size; + buf->extra_info->input_time = audio_pts / 90000; + buf->pts = audio_pts; + + if (chunk_size > buf->max_size) + buf->size = buf->max_size; + else + buf->size = chunk_size; + chunk_size -= buf->size; + + if (this->input->read(this->input, buf->content, buf->size) != + buf->size) { + buf->free_buffer(buf); + this->status = DEMUX_FINISHED; + break; + } + + if (!chunk_size) + buf->decoder_flags |= BUF_FLAG_FRAME_END; + + this->audio_fifo->put (this->audio_fifo, buf); + } + + return this->status; +} + +static void demux_aud_send_headers(demux_plugin_t *this_gen) { + + demux_aud_t *this = (demux_aud_t *) this_gen; + buf_element_t *buf; + + this->video_fifo = this->stream->video_fifo; + this->audio_fifo = this->stream->audio_fifo; + + this->status = DEMUX_OK; + + /* load stream information */ + this->stream->stream_info[XINE_STREAM_INFO_HAS_VIDEO] = 0; + this->stream->stream_info[XINE_STREAM_INFO_HAS_AUDIO] = 1; + this->stream->stream_info[XINE_STREAM_INFO_AUDIO_CHANNELS] = + this->audio_channels; + this->stream->stream_info[XINE_STREAM_INFO_AUDIO_SAMPLERATE] = + this->audio_samplerate; + this->stream->stream_info[XINE_STREAM_INFO_AUDIO_BITS] = + this->audio_bits; + + /* send start buffers */ + xine_demux_control_start(this->stream); + + /* send init info to the audio decoder */ + if (this->audio_fifo) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = this->audio_type; + buf->decoder_flags = BUF_FLAG_HEADER; + buf->decoder_info[0] = 0; + buf->decoder_info[1] = this->audio_samplerate; + buf->decoder_info[2] = this->audio_bits; + buf->decoder_info[3] = this->audio_channels; + this->audio_fifo->put (this->audio_fifo, buf); + } +} + +static int demux_aud_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time) { + + demux_aud_t *this = (demux_aud_t *) this_gen; + + /* if thread is not running, initialize demuxer */ + if( !this->stream->demux_thread_running ) { + + /* send new pts */ + xine_demux_control_newpts(this->stream, 0, 0); + + this->status = DEMUX_OK; + + /* reposition stream right after headers */ + this->input->seek(this->input, this->data_start, SEEK_SET); + } + + return this->status; +} + +static void demux_aud_dispose (demux_plugin_t *this) { + + free(this); +} + +static int demux_aud_get_status (demux_plugin_t *this_gen) { + demux_aud_t *this = (demux_aud_t *) this_gen; + + return this->status; +} + +static int demux_aud_get_stream_length (demux_plugin_t *this_gen) { + + return 0; +} + +static uint32_t demux_aud_get_capabilities(demux_plugin_t *this_gen) { + return DEMUX_CAP_NOCAP; +} + +static int demux_aud_get_optional_data(demux_plugin_t *this_gen, + void *data, int data_type) { + return DEMUX_OPTIONAL_UNSUPPORTED; +} + +static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream, + input_plugin_t *input_gen) { + + input_plugin_t *input = (input_plugin_t *) input_gen; + demux_aud_t *this; + + if (! (input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) { + printf(_("demux_aud.c: input not seekable, can not handle!\n")); + return NULL; + } + + this = xine_xmalloc (sizeof (demux_aud_t)); + this->stream = stream; + this->input = input; + + this->demux_plugin.send_headers = demux_aud_send_headers; + this->demux_plugin.send_chunk = demux_aud_send_chunk; + this->demux_plugin.seek = demux_aud_seek; + this->demux_plugin.dispose = demux_aud_dispose; + this->demux_plugin.get_status = demux_aud_get_status; + this->demux_plugin.get_stream_length = demux_aud_get_stream_length; + this->demux_plugin.get_video_frame = NULL; + this->demux_plugin.got_video_frame_cb= NULL; + this->demux_plugin.get_capabilities = demux_aud_get_capabilities; + this->demux_plugin.get_optional_data = demux_aud_get_optional_data; + this->demux_plugin.demux_class = class_gen; + + this->status = DEMUX_FINISHED; + + switch (stream->content_detection_method) { + + case METHOD_BY_CONTENT: + case METHOD_EXPLICIT: + + if (!open_aud_file(this)) { + free (this); + return NULL; + } + break; + + case METHOD_BY_EXTENSION: { + char *ending, *mrl; + + mrl = input->get_mrl (input); + + ending = strrchr(mrl, '.'); + + if (!ending) { + free (this); + return NULL; + } + + if (strncasecmp (ending, ".aud", 4)) { + free (this); + return NULL; + } + + if (!open_aud_file(this)) { + free (this); + return NULL; + } + + } + + break; + + default: + free (this); + return NULL; + } + + strncpy (this->last_mrl, input->get_mrl (input), 1024); + + return &this->demux_plugin; +} + +static char *get_description (demux_class_t *this_gen) { + return "Westwood Studios AUD file demux plugin"; +} + +static char *get_identifier (demux_class_t *this_gen) { + return "Westwood Studios AUD"; +} + +static char *get_extensions (demux_class_t *this_gen) { + return "aud"; +} + +static char *get_mimetypes (demux_class_t *this_gen) { + return NULL; +} + +static void class_dispose (demux_class_t *this_gen) { + + demux_aud_class_t *this = (demux_aud_class_t *) this_gen; + + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + demux_aud_class_t *this; + + this = xine_xmalloc (sizeof (demux_aud_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; +} + +/* + * exported plugin catalog entry + */ + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_DEMUX, 19, "aud", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/demuxers/demux_pva.c b/src/demuxers/demux_pva.c new file mode 100644 index 000000000..63162b878 --- /dev/null +++ b/src/demuxers/demux_pva.c @@ -0,0 +1,416 @@ +/* + * Copyright (C) 2000-2002 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 + * + * TechnoTrend PVA File Demuxer by Mike Melanson (melanson@pcisys.net) + * For more information regarding the PVA file format, refer to this PDF: + * http://www.technotrend.de/download/av_format_v1.pdf + * + * $Id: demux_pva.c,v 1.1 2003/01/02 06:10:49 tmmm Exp $ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include "xine_internal.h" +#include "xineutils.h" +#include "compat.h" +#include "demux.h" +#include "bswap.h" + +#define PVA_PREAMBLE_SIZE 8 + +typedef struct { + + demux_plugin_t demux_plugin; + + xine_stream_t *stream; + + config_values_t *config; + + fifo_buffer_t *video_fifo; + fifo_buffer_t *audio_fifo; + + input_plugin_t *input; + + pthread_t thread; + int thread_running; + pthread_mutex_t mutex; + int send_end_buffers; + + off_t data_start; + off_t data_size; + int status; + + char last_mrl[1024]; + +} demux_pva_t; + +typedef struct { + + demux_class_t demux_class; + + /* class-wide, global variables here */ + + xine_t *xine; + config_values_t *config; +} demux_pva_class_t; + + +/* returns 1 if the PVA file was opened successfully, 0 otherwise */ +static int open_pva_file(demux_pva_t *this) { + + unsigned char preamble[PVA_PREAMBLE_SIZE]; + + this->input->seek(this->input, 0, SEEK_SET); + if (this->input->read(this->input, preamble, PVA_PREAMBLE_SIZE) != + PVA_PREAMBLE_SIZE) + return 0; + + /* PVA file must start with signature "AV" */ + if ((preamble[0] != 'A') || (preamble[1] != 'V')) + return 0; + + /* enforce the rule that stream ID must be either 1 or 2 */ + if ((preamble[2] != 1) && (preamble[2] != 2)) + return 0; + + /* counter on the first packet should be 0 */ + if (preamble[3] != 0) + return 0; + + this->data_size = this->input->get_length(this->input); + + return 1; +} + +static int demux_pva_send_chunk(demux_plugin_t *this_gen) { + + demux_pva_t *this = (demux_pva_t *) this_gen; + buf_element_t *buf; + int chunk_size; + unsigned char preamble[PVA_PREAMBLE_SIZE]; + unsigned char pts_buf[4]; + off_t current_file_pos; + + if (this->input->read(this->input, preamble, PVA_PREAMBLE_SIZE) != + PVA_PREAMBLE_SIZE) + return 0; + + /* make sure the signature is there */ + if ((preamble[0] != 'A') || (preamble[1] != 'V')) { + this->status = DEMUX_FINISHED; + return this->status; + } + + chunk_size = BE_16(&preamble[6]); + + current_file_pos = this->input->get_current_pos(this->input) - + this->data_start; + + if (preamble[2] == 1) { + + /* video */ + buf = this->video_fifo->buffer_pool_alloc(this->video_fifo); + + /* load the pts if it is the first thing in the chunk */ + if (preamble[5] & 0x10) { + if (this->input->read(this->input, pts_buf, 4) != 4) { + buf->free_buffer(buf); + this->status = DEMUX_FINISHED; + return this->status; + } + chunk_size -= 4; + buf->pts = BE_32(&pts_buf[0]); + } else + buf->pts = 0; + + while (chunk_size) { + buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf->type = BUF_VIDEO_MPEG; + buf->extra_info->input_pos = current_file_pos; + buf->extra_info->input_length = this->data_size; + buf->extra_info->input_time = buf->pts / 90000; + + if (chunk_size > buf->max_size) + buf->size = buf->max_size; + else + buf->size = chunk_size; + chunk_size -= buf->size; + + if (this->input->read(this->input, buf->content, buf->size) != + buf->size) { + buf->free_buffer(buf); + this->status = DEMUX_FINISHED; + break; + } + + if (!chunk_size) + buf->decoder_flags |= BUF_FLAG_FRAME_END; + + this->video_fifo->put (this->video_fifo, buf); + } + + } else if (preamble[2] == 2) { + + /* audio */ + + /* skip for the time being */ + this->input->seek(this->input, chunk_size, SEEK_CUR); + + } else { + + /* unknown, skip it */ + this->input->seek(this->input, chunk_size, SEEK_CUR); + + } + + return this->status; +} + +static void demux_pva_send_headers(demux_plugin_t *this_gen) { + + demux_pva_t *this = (demux_pva_t *) this_gen; + buf_element_t *buf; + int n; + + this->video_fifo = this->stream->video_fifo; + this->audio_fifo = this->stream->audio_fifo; + + this->status = DEMUX_OK; + + /* load stream information */ + this->stream->stream_info[XINE_STREAM_INFO_HAS_VIDEO] = 1; +/* this->stream->stream_info[XINE_STREAM_INFO_HAS_AUDIO] = 1; */ + this->stream->stream_info[XINE_STREAM_INFO_HAS_AUDIO] = 0; + + /* send start buffers */ + xine_demux_control_start(this->stream); + + /* send init info to video decoder (cribbed from demux_elem.c) */ + buf = this->video_fifo->buffer_pool_alloc(this->video_fifo); + buf->content = buf->mem; + buf->type = BUF_DEMUX_BLOCK; + + n = this->input->read (this->input, buf->mem, 2048); + + if (n<=0) { + buf->free_buffer (buf); + this->status = DEMUX_FINISHED; + return; + } + + buf->size = n; + + buf->pts = 0; + buf->extra_info->input_pos = this->input->get_current_pos(this->input); + buf->type = BUF_VIDEO_MPEG; + + buf->decoder_flags = BUF_FLAG_PREVIEW; + + this->video_fifo->put(this->video_fifo, buf); + + /* send init info to the audio decoder */ + if (this->audio_fifo) { + + /* figure out the situation with PES audio */ + + } + + +} + +static int demux_pva_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time) { + + demux_pva_t *this = (demux_pva_t *) this_gen; + + /* if thread is not running, initialize demuxer */ + if( !this->stream->demux_thread_running ) { + + /* send new pts */ + xine_demux_control_newpts(this->stream, 0, 0); + + this->status = DEMUX_OK; + + /* start at the very beginning of the file */ + this->input->seek(this->input, 0, SEEK_SET); + } + + return this->status; +} + +static void demux_pva_dispose (demux_plugin_t *this) { + + free(this); +} + +static int demux_pva_get_status (demux_plugin_t *this_gen) { + demux_pva_t *this = (demux_pva_t *) this_gen; + + return this->status; +} + +static int demux_pva_get_stream_length (demux_plugin_t *this_gen) { + + return 0; +} + +static uint32_t demux_pva_get_capabilities(demux_plugin_t *this_gen) { + return DEMUX_CAP_NOCAP; +} + +static int demux_pva_get_optional_data(demux_plugin_t *this_gen, + void *data, int data_type) { + return DEMUX_OPTIONAL_UNSUPPORTED; +} + +static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream, + input_plugin_t *input_gen) { + + input_plugin_t *input = (input_plugin_t *) input_gen; + demux_pva_t *this; + + if (! (input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) { + printf(_("demux_pva.c: input not seekable, can not handle!\n")); + return NULL; + } + + this = xine_xmalloc (sizeof (demux_pva_t)); + this->stream = stream; + this->input = input; + + this->demux_plugin.send_headers = demux_pva_send_headers; + this->demux_plugin.send_chunk = demux_pva_send_chunk; + this->demux_plugin.seek = demux_pva_seek; + this->demux_plugin.dispose = demux_pva_dispose; + this->demux_plugin.get_status = demux_pva_get_status; + this->demux_plugin.get_stream_length = demux_pva_get_stream_length; + this->demux_plugin.get_video_frame = NULL; + this->demux_plugin.got_video_frame_cb= NULL; + this->demux_plugin.get_capabilities = demux_pva_get_capabilities; + this->demux_plugin.get_optional_data = demux_pva_get_optional_data; + this->demux_plugin.demux_class = class_gen; + + this->status = DEMUX_FINISHED; + + switch (stream->content_detection_method) { + + case METHOD_BY_CONTENT: + case METHOD_EXPLICIT: + + if (!open_pva_file(this)) { + free (this); + return NULL; + } + break; + + case METHOD_BY_EXTENSION: { + char *ending, *mrl; + + mrl = input->get_mrl (input); + + ending = strrchr(mrl, '.'); + + if (!ending) { + free (this); + return NULL; + } + + if (strncasecmp (ending, ".pva", 4)) { + free (this); + return NULL; + } + + if (!open_pva_file(this)) { + free (this); + return NULL; + } + + } + + break; + + default: + free (this); + return NULL; + } + + strncpy (this->last_mrl, input->get_mrl (input), 1024); + + return &this->demux_plugin; +} + +static char *get_description (demux_class_t *this_gen) { + return "TechnoTrend PVA demux plugin"; +} + +static char *get_identifier (demux_class_t *this_gen) { + return "TechnoTrend PVA"; +} + +static char *get_extensions (demux_class_t *this_gen) { + return "pva"; +} + +static char *get_mimetypes (demux_class_t *this_gen) { + return NULL; +} + +static void class_dispose (demux_class_t *this_gen) { + + demux_pva_class_t *this = (demux_pva_class_t *) this_gen; + + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + demux_pva_class_t *this; + + this = xine_xmalloc (sizeof (demux_pva_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; +} + +/* + * exported plugin catalog entry + */ + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_DEMUX, 19, "pva", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/demuxers/demux_str.c b/src/demuxers/demux_str.c new file mode 100644 index 000000000..45fd78e56 --- /dev/null +++ b/src/demuxers/demux_str.c @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2000-2002 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 + * + * STR File Demuxer by Mike Melanson (melanson@pcisys.net) + * This demuxer handles either raw STR files (which are just a concatenation + * of raw compact disc sectors) or STR files with RIFF headers. + * + * $Id: demux_str.c,v 1.1 2003/01/02 06:10:49 tmmm Exp $ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include "xine_internal.h" +#include "xineutils.h" +#include "compat.h" +#include "demux.h" +#include "bswap.h" + +/* 68 bytes is adequate for empirically determining if a file conforms */ +#define STR_CHECK_BYTES 0x68 + +#define CD_RAW_SECTOR_SIZE 2352 + +#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \ + ( (long)(unsigned char)(ch3) | \ + ( (long)(unsigned char)(ch2) << 8 ) | \ + ( (long)(unsigned char)(ch1) << 16 ) | \ + ( (long)(unsigned char)(ch0) << 24 ) ) + +#define RIFF_TAG FOURCC_TAG('R', 'I', 'F', 'F') +#define CDXA_TAG FOURCC_TAG('C', 'D', 'X', 'A') + +/* this is a temporary measure; hopefully there is a more accurate method + * for finding frame duration */ +#define FRAME_DURATION 45000 + +typedef struct { + + demux_plugin_t demux_plugin; + + xine_stream_t *stream; + + config_values_t *config; + + fifo_buffer_t *video_fifo; + fifo_buffer_t *audio_fifo; + + input_plugin_t *input; + + pthread_t thread; + int thread_running; + pthread_mutex_t mutex; + int send_end_buffers; + + off_t data_start; + off_t data_size; + int status; + + xine_bmiheader bih; + int audio_samplerate; + + char last_mrl[1024]; + +} demux_str_t; + +typedef struct { + + demux_class_t demux_class; + + /* class-wide, global variables here */ + + xine_t *xine; + config_values_t *config; +} demux_str_class_t; + + +/* returns 1 if the STR file was opened successfully, 0 otherwise */ +static int open_str_file(demux_str_t *this) { + + unsigned char check_bytes[STR_CHECK_BYTES]; + + this->bih.biWidth = this->bih.biHeight = 0; + + this->input->seek(this->input, 0, SEEK_SET); + if (this->input->read(this->input, check_bytes, STR_CHECK_BYTES) != + STR_CHECK_BYTES) + return 0; + + /* check for STR with a RIFF header */ + if ((BE_32(&check_bytes[0]) == RIFF_TAG) && + (BE_32(&check_bytes[8]) == CDXA_TAG)) + this->data_start = 0x2C; + else + this->data_start = 0; + + /* now that we have the theoretical start of the first sector, check + * if it really is a raw CD sector; first step: check for 12-byte + * sync marker */ + if ((BE_32(&check_bytes[this->data_start + 0]) != 0x00FFFFFF) || + (BE_32(&check_bytes[this->data_start + 4]) != 0xFFFFFFFF) || + (BE_32(&check_bytes[this->data_start + 8]) != 0xFFFFFF00)) + return 0; + + /* the 32 bits starting at 0x10 and at 0x14 should be the same */ + if (BE_32(&check_bytes[this->data_start + 0x10]) != + BE_32(&check_bytes[this->data_start + 0x14])) + return 0; + + /* check if this an audio or video sector (bit 1 = video, bit 2 = + * audio) */ + if ((check_bytes[this->data_start + 0x12] & 0x06) == 0x2) { + + /* video is suspected */ + + this->bih.biWidth = LE_16(&check_bytes[this->data_start + 0x28]); + this->bih.biHeight = LE_16(&check_bytes[this->data_start + 0x2A]); + + /* sanity check for the width and height */ + if ((this->bih.biWidth <= 0) || + (this->bih.biWidth > 320) || + (this->bih.biHeight <= 0) || + (this->bih.biHeight > 240)) + return 0; + + } else if ((check_bytes[this->data_start + 0x12] & 0x06) == 0x4) { + + /* audio is suspected */ + + } else + return 0; + + this->data_size = this->input->get_length(this->input) - this->data_start; + + return 1; +} + +static int demux_str_send_chunk(demux_plugin_t *this_gen) { + + demux_str_t *this = (demux_str_t *) this_gen; + unsigned char sector[CD_RAW_SECTOR_SIZE]; + unsigned int frame_number; + buf_element_t *buf; + + if (this->input->read(this->input, sector, CD_RAW_SECTOR_SIZE) != + CD_RAW_SECTOR_SIZE) { + this->status = DEMUX_FINISHED; + return this->status; + } + + if ((sector[0x12] & 0x06) == 0x2) { + + /* video chunk */ + frame_number = LE_32(§or[0x20]); + buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf->type = BUF_VIDEO_PSX_MDEC; + buf->extra_info->input_pos = + this->data_start + frame_number * CD_RAW_SECTOR_SIZE; + buf->extra_info->input_length = this->data_size; + buf->pts = frame_number * FRAME_DURATION; + buf->extra_info->input_time = buf->pts / 90000; + + /* constant size chunk */ + buf->size = 2048; + memcpy(buf->content, §or[0x38], 2048); + + /* entirely intracoded */ + buf->decoder_flags |= BUF_FLAG_KEYFRAME; + + /* if the current chunk is 1 less than the chunk count, this is the + * last chunk of the frame */ + if ((LE_16(§or[0x1C]) + 1) == LE_16(§or[0x1E])) + buf->decoder_flags |= BUF_FLAG_FRAME_END; + + this->video_fifo->put(this->video_fifo, buf); + + } else if ((sector[0x12] & 0x06) == 0x4) { + } + + return this->status; +} + +static void demux_str_send_headers(demux_plugin_t *this_gen) { + + demux_str_t *this = (demux_str_t *) this_gen; + buf_element_t *buf; + + this->video_fifo = this->stream->video_fifo; + this->audio_fifo = this->stream->audio_fifo; + + this->status = DEMUX_OK; + + /* load stream information */ + this->stream->stream_info[XINE_STREAM_INFO_HAS_VIDEO] = 1; + this->stream->stream_info[XINE_STREAM_INFO_HAS_AUDIO] = 1; + this->stream->stream_info[XINE_STREAM_INFO_VIDEO_WIDTH] = this->bih.biWidth; + this->stream->stream_info[XINE_STREAM_INFO_VIDEO_HEIGHT] = this->bih.biHeight; + + /* send start buffers */ + xine_demux_control_start(this->stream); + + /* send init info to video decoder */ + buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf->decoder_flags = BUF_FLAG_HEADER; + buf->decoder_info[0] = 0; + buf->decoder_info[1] = FRAME_DURATION; /* initial video_step */ + memcpy(buf->content, &this->bih, sizeof(this->bih)); + buf->size = sizeof(this->bih); + buf->type = BUF_VIDEO_PSX_MDEC; + this->video_fifo->put (this->video_fifo, buf); + + /* send init info to the audio decoder */ + if (this->audio_fifo) { + buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf->type = BUF_AUDIO_XA_ADPCM; + buf->decoder_flags = BUF_FLAG_HEADER; + buf->decoder_info[0] = 0; + buf->decoder_info[1] = 37800; + buf->decoder_info[2] = 16; + buf->decoder_info[3] = 1; + this->audio_fifo->put (this->audio_fifo, buf); + } +} + +static int demux_str_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time) { + + demux_str_t *this = (demux_str_t *) this_gen; + + /* if thread is not running, initialize demuxer */ + if( !this->stream->demux_thread_running ) { + + /* send new pts */ + xine_demux_control_newpts(this->stream, 0, 0); + + this->status = DEMUX_OK; + + + /* reposition at the start of the sectors */ + this->input->seek(this->input, this->data_start, SEEK_SET); + } + + return this->status; +} + +static void demux_str_dispose (demux_plugin_t *this) { + + free(this); +} + +static int demux_str_get_status (demux_plugin_t *this_gen) { + demux_str_t *this = (demux_str_t *) this_gen; + + return this->status; +} + +static int demux_str_get_stream_length (demux_plugin_t *this_gen) { + + return 0; +} + +static uint32_t demux_str_get_capabilities(demux_plugin_t *this_gen) { + return DEMUX_CAP_NOCAP; +} + +static int demux_str_get_optional_data(demux_plugin_t *this_gen, + void *data, int data_type) { + return DEMUX_OPTIONAL_UNSUPPORTED; +} + +static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream, + input_plugin_t *input_gen) { + + input_plugin_t *input = (input_plugin_t *) input_gen; + demux_str_t *this; + + if (! (input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) { + printf(_("demux_str.c: input not seekable, can not handle!\n")); + return NULL; + } + + this = xine_xmalloc (sizeof (demux_str_t)); + this->stream = stream; + this->input = input; + + this->demux_plugin.send_headers = demux_str_send_headers; + this->demux_plugin.send_chunk = demux_str_send_chunk; + this->demux_plugin.seek = demux_str_seek; + this->demux_plugin.dispose = demux_str_dispose; + this->demux_plugin.get_status = demux_str_get_status; + this->demux_plugin.get_stream_length = demux_str_get_stream_length; + this->demux_plugin.get_video_frame = NULL; + this->demux_plugin.got_video_frame_cb= NULL; + this->demux_plugin.get_capabilities = demux_str_get_capabilities; + this->demux_plugin.get_optional_data = demux_str_get_optional_data; + this->demux_plugin.demux_class = class_gen; + + this->status = DEMUX_FINISHED; + + switch (stream->content_detection_method) { + + case METHOD_BY_CONTENT: + case METHOD_EXPLICIT: + + if (!open_str_file(this)) { + free (this); + return NULL; + } + break; + + case METHOD_BY_EXTENSION: { + char *ending, *mrl; + + mrl = input->get_mrl (input); + + ending = strrchr(mrl, '.'); + + if (!ending) { + free (this); + return NULL; + } + + if (strncasecmp (ending, ".str", 4)) { + free (this); + return NULL; + } + + if (!open_str_file(this)) { + free (this); + return NULL; + } + + } + + break; + + default: + free (this); + return NULL; + } + + strncpy (this->last_mrl, input->get_mrl (input), 1024); + + return &this->demux_plugin; +} + +static char *get_description (demux_class_t *this_gen) { + return "Sony Playstation STR file demux plugin"; +} + +static char *get_identifier (demux_class_t *this_gen) { + return "PSX STR"; +} + +static char *get_extensions (demux_class_t *this_gen) { + return "str"; +} + +static char *get_mimetypes (demux_class_t *this_gen) { + return NULL; +} + +static void class_dispose (demux_class_t *this_gen) { + + demux_str_class_t *this = (demux_str_class_t *) this_gen; + + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + + demux_str_class_t *this; + + this = xine_xmalloc (sizeof (demux_str_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; +} + +/* + * exported plugin catalog entry + */ + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_DEMUX, 19, "str", XINE_VERSION_CODE, NULL, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; -- cgit v1.2.3