diff options
Diffstat (limited to 'src/demuxers')
-rw-r--r-- | src/demuxers/Makefile.am | 61 | ||||
-rw-r--r-- | src/demuxers/asfheader.c | 2 | ||||
-rw-r--r-- | src/demuxers/demux_asf.c | 6 | ||||
-rw-r--r-- | src/demuxers/demux_aud.c | 2 | ||||
-rw-r--r-- | src/demuxers/demux_film.c | 2 | ||||
-rw-r--r-- | src/demuxers/demux_flac.c | 7 | ||||
-rw-r--r-- | src/demuxers/demux_flv.c | 2 | ||||
-rw-r--r-- | src/demuxers/demux_idcin.c | 5 | ||||
-rw-r--r-- | src/demuxers/demux_matroska.c | 11 | ||||
-rw-r--r-- | src/demuxers/demux_mod.c | 14 | ||||
-rw-r--r-- | src/demuxers/demux_mpgaudio.c | 4 | ||||
-rw-r--r-- | src/demuxers/demux_nsf.c | 390 | ||||
-rw-r--r-- | src/demuxers/demux_ogg.c | 2199 | ||||
-rw-r--r-- | src/demuxers/demux_playlist.c | 746 | ||||
-rw-r--r-- | src/demuxers/demux_qt.c | 337 | ||||
-rw-r--r-- | src/demuxers/demux_real.c | 4 | ||||
-rw-r--r-- | src/demuxers/demux_realaudio.c | 2 | ||||
-rw-r--r-- | src/demuxers/demux_ts.c | 5 | ||||
-rw-r--r-- | src/demuxers/demux_tta.c | 13 | ||||
-rw-r--r-- | src/demuxers/demux_wc3movie.c | 8 | ||||
-rw-r--r-- | src/demuxers/group_audio.c | 14 | ||||
-rw-r--r-- | src/demuxers/group_audio.h | 5 | ||||
-rw-r--r-- | src/demuxers/id3.c | 8 | ||||
-rw-r--r-- | src/demuxers/id3.h | 8 |
24 files changed, 1033 insertions, 2822 deletions
diff --git a/src/demuxers/Makefile.am b/src/demuxers/Makefile.am index 83c29f4e3..ba3041d5d 100644 --- a/src/demuxers/Makefile.am +++ b/src/demuxers/Makefile.am @@ -1,30 +1,38 @@ include $(top_srcdir)/misc/Makefile.common -AM_CFLAGS = $(VISIBILITY_FLAG) +AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) AM_LDFLAGS = $(xineplug_ldflags) -if HAVE_VORBIS -ogg_module = xineplug_dmx_ogg.la -endif +## +# IMPORTANT: +# --------- +# All of xine demuxer plugins should be named like the scheme "xineplug_dmx_" -if BUILD_ASF +xineinclude_HEADERS = demux.h + +noinst_HEADERS = asfheader.h qtpalette.h group_games.h group_audio.h id3.h ebml.h matroska.h iff.h flacutils.h + +if ENABLE_ASF asf_module = xineplug_dmx_asf.la endif -if HAVE_LIBMNG +if ENABLE_MNG mng_module = xineplug_dmx_mng.la endif +if ENABLE_MODPLUG +modplug_module = xineplug_dmx_modplug.la +endif + if BUILD_DMX_IMAGE image_module = xineplug_dmx_image.la endif -## -# IMPORTANT: -# --------- -# All of xine demuxer plugins should be named like the scheme "xineplug_dmx_" - -xineplug_LTLIBRARIES = $(ogg_module) $(asf_module) $(mng_module) $(image_module) \ +xineplug_LTLIBRARIES = \ + $(asf_module) \ + $(mng_module) \ + $(image_module) \ + $(modplug_module) \ xineplug_dmx_games.la \ xineplug_dmx_audio.la \ xineplug_dmx_mpeg_ts.la \ @@ -44,11 +52,8 @@ xineplug_LTLIBRARIES = $(ogg_module) $(asf_module) $(mng_module) $(image_module) xineplug_dmx_nsv.la \ xineplug_dmx_matroska.la \ xineplug_dmx_iff.la \ - xineplug_dmx_flv.la - -xineplug_dmx_ogg_la_SOURCES = demux_ogg.c -xineplug_dmx_ogg_la_LIBADD = $(VORBIS_LIBS) $(SPEEX_LIBS) $(THEORA_LIBS) $(OGG_LIBS) $(XINE_LIB) $(LTLIBINTL) -xineplug_dmx_ogg_la_CFLAGS = $(AM_CFLAGS) $(VORBIS_CFLAGS) $(SPEEX_CFLAGS) $(THEORA_CFLAGS) $(OGG_CFLAGS) + xineplug_dmx_flv.la \ + xineplug_dmx_playlist.la xineplug_dmx_avi_la_SOURCES = demux_avi.c xineplug_dmx_avi_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) @@ -70,7 +75,7 @@ xineplug_dmx_mpeg_ts_la_LIBADD = $(XINE_LIB) xineplug_dmx_qt_la_SOURCES = demux_qt.c xineplug_dmx_qt_la_LIBADD = $(XINE_LIB) $(ZLIB_LIBS) -xineplug_dmx_qt_la_CPPFLAGS = $(ZLIB_CPPFLAGS) +xineplug_dmx_qt_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS) xineplug_dmx_asf_la_SOURCES = demux_asf.c asfheader.c xineplug_dmx_asf_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(LTLIBICONV) @@ -90,7 +95,7 @@ xineplug_dmx_rawdv_la_LIBADD = $(XINE_LIB) xineplug_dmx_mng_la_SOURCES = demux_mng.c xineplug_dmx_mng_la_LIBADD = $(XINE_LIB) $(ZLIB_LIBS) $(MNG_LIBS) -xineplug_dmx_mng_la_CPPFLAGS = $(ZLIB_CPPFLAGS) +xineplug_dmx_mng_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS) xineplug_dmx_pva_la_SOURCES = demux_pva.c xineplug_dmx_pva_la_LIBADD = $(XINE_LIB) @@ -101,17 +106,19 @@ xineplug_dmx_games_la_SOURCES = group_games.c demux_eawve.c \ demux_film.c demux_smjpeg.c demux_4xm.c \ demux_vmd.c xineplug_dmx_games_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) -xineplug_dmx_games_la_LDFLAGS = -avoid-version -module xineplug_dmx_audio_la_SOURCES = group_audio.c demux_aud.c demux_aiff.c \ - demux_cdda.c demux_mpgaudio.c demux_nsf.c \ + demux_cdda.c demux_mpgaudio.c \ demux_realaudio.c demux_snd.c demux_voc.c \ demux_vox.c demux_wav.c demux_ac3.c id3.c \ - demux_aac.c demux_mod.c demux_flac.c \ + demux_aac.c demux_flac.c \ demux_mpc.c demux_dts.c demux_shn.c \ demux_tta.c -xineplug_dmx_audio_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(LIBMODPLUG_LIBS) -xineplug_dmx_audio_la_CFLAGS = $(AM_CFLAGS) $(LIBMODPLUG_CFLAGS) +xineplug_dmx_audio_la_LIBADD = $(XINE_LIB) + +xineplug_dmx_modplug_la_SOURCES = demux_mod.c +xineplug_dmx_modplug_la_LIBADD = $(XINE_LIB) $(LIBMODPLUG_LIBS) +xineplug_dmx_modplug_la_CFLAGS = $(AM_CFLAGS) $(LIBMODPLUG_CFLAGS) xineplug_dmx_yuv_frames_la_SOURCES = demux_yuv_frames.c xineplug_dmx_yuv_frames_la_LIBADD = $(XINE_LIB) @@ -127,8 +134,8 @@ xineplug_dmx_nsv_la_LIBADD = $(XINE_LIB) xineplug_dmx_matroska_la_SOURCES = demux_matroska.c ebml.c xineplug_dmx_matroska_la_LIBADD = $(XINE_LIB) $(ZLIB_LIBS) -xineplug_dmx_matroska_la_CPPFLAGS = $(ZLIB_CPPFLAGS) xineplug_dmx_matroska_la_CFLAGS = $(AM_CFLAGS) -fno-strict-aliasing +xineplug_dmx_matroska_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS) xineplug_dmx_iff_la_SOURCES = demux_iff.c xineplug_dmx_iff_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) @@ -136,5 +143,5 @@ xineplug_dmx_iff_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) xineplug_dmx_flv_la_SOURCES = demux_flv.c xineplug_dmx_flv_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) -xineinclude_HEADERS = demux.h -noinst_HEADERS = asfheader.h qtpalette.h group_games.h group_audio.h id3.h ebml.h matroska.h iff.h flacutils.h +xineplug_dmx_playlist_la_SOURCES = demux_playlist.c +xineplug_dmx_playlist_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index ea92f878b..26a61d8fd 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -152,7 +152,7 @@ static char *asf_reader_get_string(asf_reader_t *reader, size_t size, iconv_t cd outbuf = scratch;
outbytesleft = sizeof(scratch);
reader->pos += size;
- if (iconv (cd, (ICONV_CONST char **)&inbuf, &inbytesleft, &outbuf, &outbytesleft) != -1) {
+ if (iconv (cd, (ICONV_CONST char **)&inbuf, &inbytesleft, &outbuf, &outbytesleft) != (size_t)-1) {
return strdup(scratch);
} else {
lprintf("iconv error\n");
diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index 579e0af07..447228fb0 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -2040,10 +2040,8 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, !strstr(buf,"ASX") && strncmp(buf,"[Reference]", 11) && strncmp(buf,"ASF ", 4) && - ((buf[0] != 0x30) - || (buf[1] != 0x26) - || (buf[2] != 0xb2) - || (buf[3] != 0x75))) + memcmp(buf, "\x30\x26\xB2\x75", 4) + ) return NULL; } diff --git a/src/demuxers/demux_aud.c b/src/demuxers/demux_aud.c index a6f88ff48..6223a4068 100644 --- a/src/demuxers/demux_aud.c +++ b/src/demuxers/demux_aud.c @@ -131,7 +131,7 @@ 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; + int chunk_size; off_t current_file_pos; int64_t audio_pts; buf_element_t *buf; diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c index 13036afc1..26a7a9713 100644 --- a/src/demuxers/demux_film.c +++ b/src/demuxers/demux_film.c @@ -256,7 +256,7 @@ static int open_film_file(demux_film_t *film) { film->frequency = _X_BE_32(&film_header[i + 8]); film->sample_count = _X_BE_32(&film_header[i + 12]); film->sample_table = - xine_xmalloc(film->sample_count * sizeof(film_sample_t)); + xine_xcalloc(film->sample_count, sizeof(film_sample_t)); for (j = 0; j < film->sample_count; j++) { film->sample_table[j].sample_offset = diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index 3afb5b031..9bf78ff38 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -164,8 +164,8 @@ static int open_flac_file(demux_flac_t *flac) { case 3: lprintf ("SEEKTABLE metadata, %d bytes\n", block_length); flac->seekpoint_count = block_length / FLAC_SEEKPOINT_SIZE; - flac->seekpoints = xine_xmalloc(flac->seekpoint_count * - sizeof(flac_seekpoint_t)); + flac->seekpoints = xine_xcalloc(flac->seekpoint_count, + sizeof(flac_seekpoint_t)); for (i = 0; i < flac->seekpoint_count; i++) { if (flac->input->read(flac->input, buffer, FLAC_SEEKPOINT_SIZE) != FLAC_SEEKPOINT_SIZE) return 0; @@ -191,8 +191,7 @@ static int open_flac_file(demux_flac_t *flac) { { char comments[block_length]; char *ptr = comments; - uint32_t length, user_comment_list_length; - int cn; + uint32_t length, user_comment_list_length, cn; char *comment; char c; diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index 9ccfe7e7f..aa9fae13c 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -273,7 +273,7 @@ static int parse_flv_var(demux_flv_t *this, if (key && keylen == 5 && !strncmp(key, "times", 5)) { if (this->index) free (this->index); - this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + this->index = xine_xcalloc(num, sizeof(flv_index_entry_t)); this->num_indices = num; for (num = 0; num < this->num_indices && tmp < end; num++) { if (*tmp++ == FLV_DATA_TYPE_NUMBER) { diff --git a/src/demuxers/demux_idcin.c b/src/demuxers/demux_idcin.c index 99754c797..11cb8cb9e 100644 --- a/src/demuxers/demux_idcin.c +++ b/src/demuxers/demux_idcin.c @@ -128,7 +128,7 @@ static int demux_idcin_send_chunk(demux_plugin_t *this_gen) { unsigned char disk_palette[PALETTE_SIZE * 3]; palette_entry_t palette[PALETTE_SIZE]; int i; - unsigned int remaining_sample_bytes; + int remaining_sample_bytes; int scale_bits; /* figure out what the next data is */ @@ -357,7 +357,8 @@ static void demux_idcin_send_headers(demux_plugin_t *this_gen) { demux_idcin_t *this = (demux_idcin_t *) this_gen; buf_element_t *buf; xine_bmiheader *bih = (xine_bmiheader *)this->bih; - uint32_t i, size; + uint32_t i; + int size; this->video_fifo = this->stream->video_fifo; this->audio_fifo = this->stream->audio_fifo; diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index ac0d57571..0169651a0 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -65,13 +65,6 @@ #define MAX(a, b) ((a)>(b)?(a):(b)) #endif -/* FOURCC will be manipulated using machine endian */ -#ifdef WORDS_BIGENDIAN -#define meFOURCC BE_FOURCC -#else -#define meFOURCC LE_FOURCC -#endif - typedef struct { int track_num; off_t *pos; @@ -1316,7 +1309,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { /* create a bitmap info header struct for MPEG 4 */ bih = malloc(sizeof(xine_bmiheader) + track->codec_private_len); bih->biSize = sizeof(xine_bmiheader) + track->codec_private_len; - bih->biCompression = meFOURCC('M', 'P', '4', 'S'); + bih->biCompression = ME_FOURCC('M', 'P', '4', 'S'); bih->biWidth = track->video_track->pixel_width; bih->biHeight = track->video_track->pixel_height; _x_bmiheader_le2me(bih); @@ -1337,7 +1330,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { /* create a bitmap info header struct for h264 */ bih = malloc(sizeof(xine_bmiheader) + track->codec_private_len); bih->biSize = sizeof(xine_bmiheader) + track->codec_private_len; - bih->biCompression = meFOURCC('a', 'v', 'c', '1'); + bih->biCompression = ME_FOURCC('a', 'v', 'c', '1'); bih->biWidth = track->video_track->pixel_width; bih->biHeight = track->video_track->pixel_height; _x_bmiheader_le2me(bih); diff --git a/src/demuxers/demux_mod.c b/src/demuxers/demux_mod.c index e7c6f86b3..397a952c0 100644 --- a/src/demuxers/demux_mod.c +++ b/src/demuxers/demux_mod.c @@ -31,8 +31,6 @@ #include "config.h" #endif -#ifdef HAVE_MODPLUG - #include <stdio.h> #include <fcntl.h> #include <unistd.h> @@ -48,7 +46,6 @@ #include "xineutils.h" #include "compat.h" #include "demux.h" -#include "group_audio.h" #include "modplug.h" #include "bswap.h" @@ -377,7 +374,7 @@ static void class_dispose (demux_class_t *this_gen) { free (this); } -void *demux_mod_init_plugin (xine_t *xine, void *data) { +static void *demux_mod_init_plugin (xine_t *xine, void *data) { demux_mod_class_t *this; this = xine_xmalloc (sizeof (demux_mod_class_t)); @@ -392,4 +389,11 @@ void *demux_mod_init_plugin (xine_t *xine, void *data) { return this; } -#endif /* HAVE_MODPLUG */ +static const demuxer_info_t demux_info_mod = { + 10 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + { PLUGIN_DEMUX, 26, "modplug", XINE_VERSION_CODE, &demux_info_mod, demux_mod_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 73e43c199..9c997c9f5 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -410,7 +410,7 @@ static vbri_header_t* parse_vbri_header(mpg_audio_frame_t *frame, lprintf("entry_frames: %d\n", vbri->entry_frames); if ((ptr + (vbri->toc_entries + 1) * vbri->entry_size) >= (buf + bufsize)) return 0; - vbri->toc = xine_xmalloc (sizeof(int) * (vbri->toc_entries + 1)); + vbri->toc = xine_xcalloc ((vbri->toc_entries + 1), sizeof(int)); if (!vbri->toc) { free (vbri); return NULL; @@ -694,7 +694,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) { * id3v2 are not specific to mp3 files, * flac files can contain id3v2 tags */ - uint32_t tag_size = _X_BE_32_synchsafe(&buf[6]); + int tag_size = _X_BE_32_synchsafe(&buf[6]); lprintf("try to skip id3v2 tag (%d bytes)\n", tag_size); if ((10 + tag_size) >= preview_len) { lprintf("cannot skip id3v2 tag\n"); diff --git a/src/demuxers/demux_nsf.c b/src/demuxers/demux_nsf.c deleted file mode 100644 index 81f42044f..000000000 --- a/src/demuxers/demux_nsf.c +++ /dev/null @@ -1,390 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - */ - -/* - * NSF File "Demuxer" by Mike Melanson (melanson@pcisys.net) - * This is really just a loader for NES Music File Format (extension NSF) - * which loads an entire NSF file and passes it over to the NSF audio - * decoder. - * - * After the file is sent over, the demuxer controls the playback by - * sending empty buffers with incrementing pts values. - * - * For more information regarding the NSF format, visit: - * http://www.tripoint.org/kevtris/nes/nsfspec.txt - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> - -/********** logging **********/ -#define LOG_MODULE "demux_nsf" -/* #define LOG_VERBOSE */ -/* #define LOG */ - -#include "xine_internal.h" -#include "xineutils.h" -#include "compat.h" -#include "demux.h" -#include "bswap.h" -#include "group_audio.h" - -#define NSF_HEADER_SIZE 0x80 -#define NSF_SAMPLERATE 44100 -#define NSF_BITS 8 -#define NSF_CHANNELS 1 -#define NSF_REFRESH_RATE 60 -#define NSF_PTS_INC (90000 / NSF_REFRESH_RATE) - -typedef struct { - demux_plugin_t demux_plugin; - - xine_stream_t *stream; - fifo_buffer_t *video_fifo; - fifo_buffer_t *audio_fifo; - input_plugin_t *input; - int status; - - int total_songs; - int current_song; - int new_song; /* indicates song change */ - - char *title; - char *artist; - char *copyright; - - off_t filesize; - - int64_t current_pts; - int file_sent; -} demux_nsf_t; - -typedef struct { - demux_class_t demux_class; -} demux_nsf_class_t; - -/* returns 1 if the NSF file was opened successfully, 0 otherwise */ -static int open_nsf_file(demux_nsf_t *this) { - unsigned char header[NSF_HEADER_SIZE]; - - this->input->seek(this->input, 0, SEEK_SET); - if (this->input->read(this->input, header, NSF_HEADER_SIZE) != - NSF_HEADER_SIZE) - return 0; - - /* check for the signature */ - if ((header[0] != 'N') || - (header[1] != 'E') || - (header[2] != 'S') || - (header[3] != 'M') || - (header[4] != 0x1A)) - return 0; - - this->total_songs = header[6]; - this->current_song = header[7]; - this->title = strdup(&header[0x0E]); - this->artist = strdup(&header[0x2E]); - this->copyright = strdup(&header[0x4E]); - - this->filesize = this->input->get_length(this->input); - - return 1; -} - -static int demux_nsf_send_chunk(demux_plugin_t *this_gen) { - demux_nsf_t *this = (demux_nsf_t *) this_gen; - buf_element_t *buf; - int bytes_read; - char title[100]; - - /* send chunks of the file to the decoder until file is completely - * loaded; then send control buffers */ - if (!this->file_sent) { - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - buf->type = BUF_AUDIO_NSF; - bytes_read = this->input->read(this->input, buf->content, buf->max_size); - - if (bytes_read == 0) { - /* the file has been completely loaded, free the buffer and start - * sending control buffers */ - buf->free_buffer(buf); - this->file_sent = 1; - - } else { - - /* keep loading the file */ - if (bytes_read < buf->max_size) - buf->size = bytes_read; - else - buf->size = buf->max_size; - - buf->extra_info->input_normpos = 0; - buf->extra_info->input_time = 0; - buf->pts = 0; - - this->audio_fifo->put (this->audio_fifo, buf); - } - } - - /* this is not an 'else' because control might fall through from above */ - if (this->file_sent) { - /* send a control buffer */ - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - - if (this->new_song) { - - buf->decoder_info[1] = this->current_song; - this->new_song = 0; - sprintf(title, "%s, song %d/%d", - this->title, this->current_song, this->total_songs); - - _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, title); - - _x_demux_control_newpts(this->stream, this->current_pts, 0); - - } else - buf->decoder_info[1] = 0; - - buf->type = BUF_AUDIO_NSF; - if(this->total_songs) - buf->extra_info->input_normpos = (this->current_song - 1) * 65535 / this->total_songs; - buf->extra_info->input_time = this->current_pts / 90; - buf->pts = this->current_pts; - buf->size = 0; - this->audio_fifo->put (this->audio_fifo, buf); - - this->current_pts += NSF_PTS_INC; - } - - return this->status; -} - -static void demux_nsf_send_headers(demux_plugin_t *this_gen) { - demux_nsf_t *this = (demux_nsf_t *) this_gen; - buf_element_t *buf; - char copyright[100]; - - this->video_fifo = this->stream->video_fifo; - this->audio_fifo = this->stream->audio_fifo; - - this->status = DEMUX_OK; - - /* load stream information */ - _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, - NSF_CHANNELS); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, - NSF_SAMPLERATE); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, - NSF_BITS); - - _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, this->title); - _x_meta_info_set(this->stream, XINE_META_INFO_ARTIST, this->artist); - sprintf(copyright, "(C) %s", this->copyright); - _x_meta_info_set(this->stream, XINE_META_INFO_COMMENT, copyright); - - /* send start buffers */ - _x_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 = BUF_AUDIO_NSF; - buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_FRAME_END; - buf->decoder_info[0] = 5; - buf->decoder_info[1] = NSF_SAMPLERATE; - buf->decoder_info[2] = NSF_BITS; - buf->decoder_info[3] = NSF_CHANNELS; - - /* send the NSF filesize in the body, big endian format */ - buf->content[0] = (this->filesize >> 24) & 0xFF; - buf->content[1] = (this->filesize >> 16) & 0xFF; - buf->content[2] = (this->filesize >> 8) & 0xFF; - buf->content[3] = (this->filesize >> 0) & 0xFF; - /* send the requested song */ - buf->content[4] = this->current_song + 5; - - this->audio_fifo->put (this->audio_fifo, buf); - } -} - -static int demux_nsf_seek (demux_plugin_t *this_gen, - off_t start_pos, int start_time, int playing) { - - demux_nsf_t *this = (demux_nsf_t *) this_gen; - start_pos = (off_t) ( (double) start_pos / 65535 * - this->total_songs ); - - /* if thread is not running, initialize demuxer */ - if( !playing ) { - - /* send new pts */ - _x_demux_control_newpts(this->stream, 0, 0); - - this->status = DEMUX_OK; - - /* reposition stream at the start for loading */ - this->input->seek(this->input, 0, SEEK_SET); - - this->file_sent = 0; - this->current_pts = 0; - this->new_song = 1; - } else { - this->current_song = start_pos + 1; - this->new_song = 1; - this->current_pts = 0; - _x_demux_flush_engine(this->stream); - } - - return this->status; -} - -static void demux_nsf_dispose (demux_plugin_t *this_gen) { - demux_nsf_t *this = (demux_nsf_t *) this_gen; - - free(this->title); - free(this->artist); - free(this->copyright); - free(this); -} - -static int demux_nsf_get_status (demux_plugin_t *this_gen) { - demux_nsf_t *this = (demux_nsf_t *) this_gen; - - return this->status; -} - -/* return the approximate length in miliseconds */ -static int demux_nsf_get_stream_length (demux_plugin_t *this_gen) { - return 0; -} - -static uint32_t demux_nsf_get_capabilities(demux_plugin_t *this_gen) { - return DEMUX_CAP_NOCAP; -} - -static int demux_nsf_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) { - - demux_nsf_t *this; - - if (!INPUT_IS_SEEKABLE(input)) { - xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "input not seekable, can not handle!\n"); - return NULL; - } - - this = xine_xmalloc (sizeof (demux_nsf_t)); - this->stream = stream; - this->input = input; - - this->demux_plugin.send_headers = demux_nsf_send_headers; - this->demux_plugin.send_chunk = demux_nsf_send_chunk; - this->demux_plugin.seek = demux_nsf_seek; - this->demux_plugin.dispose = demux_nsf_dispose; - this->demux_plugin.get_status = demux_nsf_get_status; - this->demux_plugin.get_stream_length = demux_nsf_get_stream_length; - this->demux_plugin.get_capabilities = demux_nsf_get_capabilities; - this->demux_plugin.get_optional_data = demux_nsf_get_optional_data; - this->demux_plugin.demux_class = class_gen; - - this->status = DEMUX_FINISHED; - - switch (stream->content_detection_method) { - - case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); - - if (!_x_demux_check_extension (mrl, extensions)) { - free (this); - return NULL; - } - } - /* falling through is intended */ - - case METHOD_BY_CONTENT: - case METHOD_EXPLICIT: - - if (!open_nsf_file(this)) { - free (this); - return NULL; - } - - break; - - default: - free (this); - return NULL; - } - - return &this->demux_plugin; -} - -static const char *get_description (demux_class_t *this_gen) { - return "NES Music file demux plugin"; -} - -static const char *get_identifier (demux_class_t *this_gen) { - return "NSF"; -} - -static const char *get_extensions (demux_class_t *this_gen) { - return "nsf"; -} - -static const char *get_mimetypes (demux_class_t *this_gen) { - return NULL; -} - -static void class_dispose (demux_class_t *this_gen) { - demux_nsf_class_t *this = (demux_nsf_class_t *) this_gen; - - free (this); -} - -void *demux_nsf_init_plugin (xine_t *xine, void *data) { - demux_nsf_class_t *this; - - this = xine_xmalloc (sizeof (demux_nsf_class_t)); - - 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/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c deleted file mode 100644 index eb4f7ba5a..000000000 --- a/src/demuxers/demux_ogg.c +++ /dev/null @@ -1,2199 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - */ - -/* - * demultiplexer for ogg streams - */ -/* 2003.02.09 (dilb) update of the handling for audio/video infos for strongarm cpus. */ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <stdlib.h> -#include <inttypes.h> - -#include <ogg/ogg.h> -#include <vorbis/codec.h> - -#ifdef HAVE_SPEEX -#include <speex/speex.h> -#include <speex/speex_header.h> -#include <speex/speex_stereo.h> -#include <speex/speex_callbacks.h> -#endif - -#ifdef HAVE_THEORA -#include <theora/theora.h> -#endif - -#define LOG_MODULE "demux_ogg" -#define LOG_VERBOSE - -/* -#define LOG -*/ - -#define DEBUG_PACKETS 0 -#define DEBUG_PREVIEWS 0 -#define DEBUG_PTS 0 -#define DEBUG_VIDEO_PACKETS 0 - -#include "xine_internal.h" -#include "xineutils.h" -#include "demux.h" -#include "bswap.h" -#include "flacutils.h" - -#define CHUNKSIZE 8500 -#define PACKET_TYPE_HEADER 0x01 -#define PACKET_TYPE_COMMENT 0x03 -#define PACKET_TYPE_CODEBOOK 0x05 -#define PACKET_TYPE_BITS 0x07 -#define PACKET_LEN_BITS01 0xc0 -#define PACKET_LEN_BITS2 0x02 -#define PACKET_IS_SYNCPOINT 0x08 - -#define MAX_STREAMS 32 - -#define PTS_AUDIO 0 -#define PTS_VIDEO 1 - -#define WRAP_THRESHOLD 900000 - -#define SUB_BUFSIZE 1024 - -typedef struct chapter_entry_s { - int64_t start_pts; - char *name; -} chapter_entry_t; - -typedef struct chapter_info_s { - int current_chapter; - int max_chapter; - chapter_entry_t *entries; -} chapter_info_t; - -typedef struct stream_info_s { - ogg_stream_state oss; - uint32_t buf_types; - int headers; - int64_t header_granulepos; - int64_t factor; - int64_t quotient; - int resync; - char *language; - /* CMML, Ogg Skeleton stream information */ - int granuleshift; - /* Annodex v2 stream information */ - int hide_first_header; - int delivered_bos; - int delivered_eos; -} stream_info_t; - -typedef struct demux_ogg_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 frame_duration; - -#ifdef HAVE_THEORA - theora_info t_info; - theora_comment t_comment; -#endif - - ogg_sync_state oy; - ogg_page og; - - int64_t start_pts; - int64_t last_pts[2]; - - int time_length; - - int num_streams; - stream_info_t *si[MAX_STREAMS]; /* stream info */ - - int num_audio_streams; - int num_video_streams; - int unhandled_video_streams; - int num_spu_streams; - - off_t avg_bitrate; - - char *title; - chapter_info_t *chapter_info; - xine_event_queue_t *event_queue; - - uint8_t send_newpts:1; - uint8_t buf_flag_seek:1; - uint8_t keyframe_needed:1; - uint8_t ignore_keyframes:1; -} demux_ogg_t ; - -typedef struct { - demux_class_t demux_class; -} demux_ogg_class_t; - -typedef struct { - demux_class_t demux_class; -} demux_anx_class_t; - - -#ifdef HAVE_THEORA -static int intlog(int num) { - int ret=0; - - while(num>0){ - num=num/2; - ret=ret+1; - } - return(ret); -} -#endif - -static int get_stream (demux_ogg_t *this, int serno) { - /*finds the stream_num, which belongs to a ogg serno*/ - int i; - - for (i = 0; i<this->num_streams; i++) { - if (this->si[i]->oss.serialno == serno) { - return i; - } - } - return -1; -} - -static int new_stream_info (demux_ogg_t *this, const int cur_serno) { - int stream_num; - - this->si[this->num_streams] = (stream_info_t *)xine_xmalloc(sizeof(stream_info_t)); - ogg_stream_init(&this->si[this->num_streams]->oss, cur_serno); - stream_num = this->num_streams; - this->si[stream_num]->buf_types = 0; - this->si[stream_num]->header_granulepos = -1; - this->si[stream_num]->headers = 0; - this->num_streams++; - - return stream_num; -} - -static int64_t get_pts (demux_ogg_t *this, int stream_num , int64_t granulepos ) { - /*calculates an pts from an granulepos*/ - if (granulepos<0) { - if ( this->si[stream_num]->header_granulepos>=0 ) { - /*return the smallest valid pts*/ - return 1; - } else - return 0; - } else if (this->si[stream_num]->buf_types == BUF_VIDEO_THEORA || - (this->si[stream_num]->buf_types & 0xFFFF0000) == BUF_SPU_CMML) { - int64_t iframe, pframe; - int granuleshift; - granuleshift = this->si[stream_num]->granuleshift; - iframe = granulepos >> granuleshift; - pframe = granulepos - (iframe << granuleshift); - if (this->si[stream_num]->quotient) - return 1+((iframe+pframe) * this->si[stream_num]->factor / this->si[stream_num]->quotient); - else - return 0; - } else if (this->si[stream_num]->quotient) - return 1+(granulepos * this->si[stream_num]->factor / this->si[stream_num]->quotient); - else - return 0; -} - -static int read_ogg_packet (demux_ogg_t *this) { - char *buffer; - long bytes; - while (ogg_sync_pageout(&this->oy,&this->og)!=1) { - buffer = ogg_sync_buffer(&this->oy, CHUNKSIZE); - bytes = this->input->read(this->input, buffer, CHUNKSIZE); - ogg_sync_wrote(&this->oy, bytes); - if (bytes < CHUNKSIZE/2) { - return 0; - } - } - return 1; -} - -static void get_stream_length (demux_ogg_t *this) { - /*determine the streamlenght and set this->time_length accordingly. - ATTENTION:current_pos and oggbuffers will be destroyed by this function, - there will be no way to continue playback uninterrupted. - - You have to seek afterwards, because after get_stream_length, the - current_position is at the end of the file */ - - off_t filelength; - int done=0; - int stream_num; - - this->time_length=-1; - - if (this->input->get_capabilities(this->input) & INPUT_CAP_SEEKABLE) { - filelength=this->input->get_length(this->input); - - if (filelength!=-1) { - if (filelength>70000) { - this->demux_plugin.seek(&this->demux_plugin, - (off_t) ( (double)(filelength-65536)/filelength*65535), 0, 0); - } - done=0; - while (!done) { - if (!read_ogg_packet (this)) { - if (this->time_length) { - _x_stream_info_set(this->stream, XINE_STREAM_INFO_BITRATE, - ((int64_t) 8000*filelength)/this->time_length); - /*this is a fine place to compute avg_bitrate*/ - this->avg_bitrate= 8000*filelength/this->time_length; - } - return; - } - stream_num=get_stream(this, ogg_page_serialno (&this->og) ); - if (stream_num!=-1) { - if (this->time_length < (get_pts(this, stream_num, ogg_page_granulepos(&this->og) / 90))) - this->time_length = get_pts(this, stream_num, ogg_page_granulepos(&this->og)) / 90; - } - } - } - } -} - -#ifdef HAVE_THEORA -static void send_ogg_packet (demux_ogg_t *this, - fifo_buffer_t *fifo, - ogg_packet *op, - int64_t pts, - uint32_t decoder_flags, - int stream_num) { - - buf_element_t *buf; - - int done=0,todo=op->bytes; - int op_size = sizeof(ogg_packet); - - while (done<todo) { - int offset=0; - buf = fifo->buffer_pool_alloc (fifo); - buf->decoder_flags = decoder_flags; - if (done==0) { - memcpy (buf->content, op, op_size); - offset=op_size; - buf->decoder_flags = buf->decoder_flags | BUF_FLAG_FRAME_START; - } - - if (done+buf->max_size-offset < todo) { - memcpy (buf->content+offset, op->packet+done, buf->max_size-offset); - buf->size = buf->max_size; - done=done+buf->max_size-offset; - } else { - memcpy (buf->content+offset , op->packet+done, todo-done); - buf->size = todo-done+offset; - done=todo; - buf->decoder_flags = buf->decoder_flags | BUF_FLAG_FRAME_END; - } - - buf->pts = pts; - if( this->input->get_length (this->input) ) - buf->extra_info->input_normpos = (int)( (double) this->input->get_current_pos (this->input) * - 65535 / this->input->get_length (this->input) ); - buf->extra_info->input_time = buf->pts / 90 ; - buf->type = this->si[stream_num]->buf_types; - - fifo->put (fifo, buf); - } -} -#endif - -/* redefine abs as macro to handle 64-bit diffs. - i guess llabs may not be available everywhere */ -#define abs(x) ( ((x)<0) ? -(x) : (x) ) - -static void check_newpts (demux_ogg_t *this, int64_t pts, int video, int preview) { - int64_t diff; - - llprintf(DEBUG_PTS, "new pts %" PRId64 " found in stream\n",pts); - - diff = pts - this->last_pts[video]; - - if (!preview && (pts>=0) && - (this->send_newpts || (this->last_pts[video] && abs(diff)>WRAP_THRESHOLD) ) ) { - - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "diff=%" PRId64 " (pts=%" PRId64 ", last_pts=%" PRId64 ")\n", diff, pts, this->last_pts[video]); - - if (this->buf_flag_seek) { - _x_demux_control_newpts(this->stream, pts, BUF_FLAG_SEEK); - this->buf_flag_seek = 0; - } else { - _x_demux_control_newpts(this->stream, pts, 0); - } - this->send_newpts = 0; - this->last_pts[1-video] = 0; - } - - if (!preview && (pts>=0) ) - this->last_pts[video] = pts; - - /* use pts for bitrate measurement */ - - /*compute avg_bitrate if time_length isn't set*/ - if ((pts>180000) && !(this->time_length)) { - this->avg_bitrate = this->input->get_current_pos (this->input) * 8 * 90000/ pts; - - if (this->avg_bitrate<1) - this->avg_bitrate = 1; - - } -} - -static void ogg_handle_event (demux_ogg_t *this) { - xine_event_t *event; - - while ((event = xine_event_get(this->event_queue))) { - switch(event->type) { - case XINE_EVENT_INPUT_NEXT: - { - if (this->chapter_info) { - int c_chap = this->chapter_info->current_chapter; - if (c_chap+1 < this->chapter_info->max_chapter) { - int start_time = this->chapter_info->entries[c_chap+1].start_pts / 90; - this->demux_plugin.seek((demux_plugin_t *)this, 0, start_time, 1); - } - } - } - break; - case XINE_EVENT_INPUT_PREVIOUS: - { - if (this->chapter_info) { - int c_chap = this->chapter_info->current_chapter; - if (c_chap >= 1) { - int start_time = this->chapter_info->entries[c_chap-1].start_pts / 90; - this->demux_plugin.seek((demux_plugin_t *)this, 0, start_time, 1); - } - } - } - break; - } - xine_event_free(event); - } - return; -} - -/* - * utility function to read a LANGUAGE= line from the user_comments, - * to label audio and spu streams - */ -static void read_language_comment (demux_ogg_t *this, ogg_packet *op, int stream_num) { - char **ptr; - char *comment; - vorbis_comment vc; - vorbis_info vi; - - vorbis_comment_init(&vc); - vorbis_info_init(&vi); - - /* this is necessary to make libvorbis accept this vorbis_info*/ - vi.rate=1; - - if ( vorbis_synthesis_headerin(&vi, &vc, op) >= 0) { - ptr=vc.user_comments; - while(*ptr) { - comment=*ptr; - if ( !strncasecmp ("LANGUAGE=", comment, 9) ) { - this->si[stream_num]->language = strdup (comment + strlen ("LANGUAGE=") ); - } - ++ptr; - } - } - vorbis_comment_clear(&vc); - vorbis_info_clear(&vi); -} - -/* - * utility function to read CHAPTER*= and TITLE= from the user_comments, - * to name parts of the videostream - */ -static void read_chapter_comment (demux_ogg_t *this, ogg_packet *op) { - char **ptr; - char *comment; - vorbis_comment vc; - vorbis_info vi; - - vorbis_comment_init(&vc); - vorbis_info_init(&vi); - - /* this is necessary to make libvorbis accept this vorbis_info*/ - vi.rate=1; - - if ( vorbis_synthesis_headerin(&vi, &vc, op) >= 0) { - char *chapter_time = 0; - char *chapter_name = 0; - int chapter_no = 0; - ptr=vc.user_comments; - while(*ptr) { - comment=*ptr; - if ( !strncasecmp ("TITLE=", comment,6) ) { - this->title = strdup (comment + strlen ("TITLE=") ); - _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, this->title); - } - if ( !chapter_time && strlen(comment) == 22 && - !strncasecmp ("CHAPTER" , comment, 7) && - isdigit(*(comment+7)) && isdigit(*(comment+8)) && - (*(comment+9) == '=')) { - - chapter_time = strdup(comment+10); - chapter_no = strtol(comment+7, NULL, 10); - } - if ( !chapter_name && !strncasecmp("CHAPTER", comment, 7) && - isdigit(*(comment+7)) && isdigit(*(comment+8)) && - !strncasecmp ("NAME=", comment+9, 5)) { - - if (strtol(comment+7,NULL,10) == chapter_no) { - chapter_name = strdup(comment+14); - } - } - if (chapter_time && chapter_name && chapter_no){ - int hour, min, sec, msec; - - lprintf("create chapter entry: no=%d name=%s time=%s\n", chapter_no, chapter_name, chapter_time); - hour= strtol(chapter_time, NULL, 10); - min = strtol(chapter_time+3, NULL, 10); - sec = strtol(chapter_time+6, NULL, 10); - msec = strtol(chapter_time+9, NULL, 10); - lprintf("time: %d %d %d %d\n", hour, min,sec,msec); - - if (!this->chapter_info) { - this->chapter_info = (chapter_info_t *)xine_xmalloc(sizeof(chapter_info_t)); - this->chapter_info->current_chapter = -1; - } - this->chapter_info->max_chapter = chapter_no; - this->chapter_info->entries = realloc( this->chapter_info->entries, chapter_no*sizeof(chapter_entry_t)); - this->chapter_info->entries[chapter_no-1].name = chapter_name; - this->chapter_info->entries[chapter_no-1].start_pts = (msec + (1000.0 * sec) + (60000.0 * min) + (3600000.0 * hour))*90; - - free (chapter_time); - chapter_no = 0; - chapter_time = chapter_name = 0; - } - ++ptr; - } - } - vorbis_comment_clear(&vc); - vorbis_info_clear(&vi); -} - -/* - * update the display of the title, if needed - */ -static void update_chapter_display (demux_ogg_t *this, int stream_num, ogg_packet *op) { - int chapter = 0; - int64_t pts = get_pts(this, stream_num, op->granulepos ); - - while (chapter < this->chapter_info->max_chapter && - this->chapter_info->entries[chapter].start_pts < pts) { - chapter++; - } - chapter--; - - if (chapter != this->chapter_info->current_chapter){ - xine_event_t uevent; - xine_ui_data_t data; - int title_len; - char *title; - - this->chapter_info->current_chapter = chapter; - if (chapter >= 0) { - char t_title[256]; - - if (this->title) { - snprintf(t_title, sizeof (t_title), "%s / %s", this->title, this->chapter_info->entries[chapter].name); - } else { - snprintf(t_title, sizeof (t_title), "%s", this->chapter_info->entries[chapter].name); - } - title = t_title; - } else { - title = this->title; - } - _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, title); - lprintf("new TITLE: %s\n", title); - - uevent.type = XINE_EVENT_UI_SET_TITLE; - uevent.stream = this->stream; - uevent.data = &data; - uevent.data_length = sizeof(data); - title_len = strlen(title) + 1; - memcpy(data.str, title, title_len); - data.str_len = title_len; - xine_event_send(this->stream, &uevent); - } -} - -/* - * utility function to pack one ogg_packet into a xine - * buffer, fill out all needed fields - * and send it to the right fifo - */ - -static void send_ogg_buf (demux_ogg_t *this, - ogg_packet *op, - int stream_num, - uint32_t decoder_flags) { - - int hdrlen; - int normpos = 0; - - if( this->input->get_length (this->input) ) - normpos = (int)( (double) this->input->get_current_pos (this->input) * - 65535 / this->input->get_length (this->input) ); - - - hdrlen = (*op->packet & PACKET_LEN_BITS01) >> 6; - hdrlen |= (*op->packet & PACKET_LEN_BITS2) << 1; - - /* for Annodex files: the first packet after the AnxData info packet needs - * to have its BOS flag set: we set it here */ - if (!this->si[stream_num]->delivered_bos) { - op->b_o_s = 1; - this->si[stream_num]->delivered_bos = 1; - } - - if ( this->audio_fifo - && (this->si[stream_num]->buf_types & 0xFF000000) == BUF_AUDIO_BASE) { - uint8_t *data; - int size; - int64_t pts; - - if (op->packet[0] == PACKET_TYPE_COMMENT ) { - read_language_comment(this, op, stream_num); - } - - if ((this->si[stream_num]->buf_types & 0xFFFF0000) == BUF_AUDIO_SPEEX || - (this->si[stream_num]->buf_types & 0xFFFF0000) == BUF_AUDIO_FLAC || - (this->si[stream_num]->buf_types & 0xFFFF0000) == BUF_AUDIO_VORBIS) { - data = op->packet; - size = op->bytes; - } else { - data = op->packet+1+hdrlen; - size = op->bytes-1-hdrlen; - } - llprintf(DEBUG_PACKETS, "audio data size %d\n", size); - - if ((op->granulepos != -1) || (this->si[stream_num]->header_granulepos != -1)) { - pts = get_pts(this, stream_num, op->granulepos ); - check_newpts( this, pts, PTS_AUDIO, decoder_flags ); - } else - pts = 0; - - llprintf(DEBUG_PACKETS, - "audiostream %d op-gpos %" PRId64 " hdr-gpos %" PRId64 " pts %" PRId64 " \n", - stream_num, - op->granulepos, - this->si[stream_num]->header_granulepos, - pts); - - _x_demux_send_data(this->audio_fifo, data, size, - pts, this->si[stream_num]->buf_types, decoder_flags, - normpos, - pts / 90, this->time_length, 0); - -#ifdef HAVE_THEORA - } else if ((this->si[stream_num]->buf_types & 0xFFFF0000) == BUF_VIDEO_THEORA) { - - int64_t pts; - theora_info t_info; - theora_comment t_comment; - - theora_info_init (&t_info); - theora_comment_init (&t_comment); - - /*Lets see if this is an Header*/ - if ((theora_decode_header(&t_info, &t_comment, op))>=0) { - decoder_flags=decoder_flags|BUF_FLAG_HEADER; - lprintf ("found an header\n"); - } - - if ((op->granulepos != -1) || (this->si[stream_num]->header_granulepos != -1)) { - pts = get_pts(this, stream_num, op->granulepos ); - check_newpts( this, pts, PTS_VIDEO, decoder_flags ); - } else - pts = 0; - - llprintf(DEBUG_PACKETS, - "theorastream %d op-gpos %" PRId64 " hdr-gpos %" PRId64 " pts %" PRId64 " \n", - stream_num, - op->granulepos, - this->si[stream_num]->header_granulepos, - pts); - - send_ogg_packet (this, this->video_fifo, op, pts, decoder_flags, stream_num); - - theora_comment_clear (&t_comment); - theora_info_clear (&t_info); -#endif - - } else if ((this->si[stream_num]->buf_types & 0xFF000000) == BUF_VIDEO_BASE) { - - uint8_t *data; - int size; - int64_t pts; - - llprintf(DEBUG_VIDEO_PACKETS, - "video buffer, type=%08x\n", this->si[stream_num]->buf_types); - - if (op->packet[0] == PACKET_TYPE_COMMENT ) { - read_chapter_comment(this, op); - }else{ - data = op->packet+1+hdrlen; - size = op->bytes-1-hdrlen; - - if ((op->granulepos != -1) || (this->si[stream_num]->header_granulepos != -1)) { - pts = get_pts(this, stream_num, op->granulepos ); - check_newpts( this, pts, PTS_VIDEO, decoder_flags ); - } else - pts = 0; - - llprintf(DEBUG_VIDEO_PACKETS, - "videostream %d op-gpos %" PRId64 " hdr-gpos %" PRId64 " pts %" PRId64 " \n", - stream_num, - op->granulepos, - this->si[stream_num]->header_granulepos, - pts); - - _x_demux_send_data(this->video_fifo, data, size, - pts, this->si[stream_num]->buf_types, decoder_flags, - normpos, - pts / 90, this->time_length, 0); - - if (this->chapter_info && op->granulepos != -1) { - update_chapter_display(this, stream_num, op); - } - } - } else if ((this->si[stream_num]->buf_types & 0xFFFF0000) == BUF_SPU_CMML) { - buf_element_t *buf; - uint32_t *val; - char *str; - - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - - buf->type = this->si[stream_num]->buf_types; - - buf->pts = get_pts (this, stream_num, op->granulepos); - - val = (uint32_t * )buf->content; - str = (char *)val; - - memcpy(str, op->packet, op->bytes); - str[op->bytes] = '\0'; - - buf->size = 12 + op->bytes + 1; - - lprintf ("CMML stream %d (bytes=%ld): PTS %"PRId64": %s\n", - stream_num, op->bytes, buf->pts, str); - - this->video_fifo->put (this->video_fifo, buf); - } else if ((this->si[stream_num]->buf_types & 0xFF000000) == BUF_SPU_BASE) { - - buf_element_t *buf; - int i; - char *subtitle,*str; - int lenbytes; - int start,end; - uint32_t *val; - - for (i = 0, lenbytes = 0; i < hdrlen; i++) { - lenbytes = lenbytes << 8; - lenbytes += *((unsigned char *) op->packet + hdrlen - i); - } - - if (op->packet[0] == PACKET_TYPE_HEADER ) { - lprintf ("Textstream-header-packet\n"); - } else if (op->packet[0] == PACKET_TYPE_COMMENT ) { - lprintf ("Textstream-comment-packet\n"); - read_language_comment(this, op, stream_num); - } else { - subtitle = (char *)&op->packet[hdrlen + 1]; - - if ((strlen(subtitle) > 1) || (*subtitle != ' ')) { - start = op->granulepos; - end = start+lenbytes; - lprintf ("subtitlestream %d: %d -> %d :%s\n",stream_num,start,end,subtitle); - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - - buf->type = this->si[stream_num]->buf_types; - buf->pts = 0; - - val = (uint32_t * )buf->content; - *val++ = start; - *val++ = end; - str = (char *)val; - - memcpy (str, subtitle, 1+strlen(subtitle)); - - this->video_fifo->put (this->video_fifo, buf); - } - } - } else { - lprintf("unknown stream type %x\n", this->si[stream_num]->buf_types); - } -} - -static void decode_vorbis_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - vorbis_info vi; - vorbis_comment vc; - - this->si[stream_num]->buf_types = BUF_AUDIO_VORBIS - +this->num_audio_streams++; - - this->si[stream_num]->headers = 3; - - vorbis_info_init(&vi); - vorbis_comment_init(&vc); - if (vorbis_synthesis_headerin(&vi, &vc, op) >= 0) { - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, vi.bitrate_nominal); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, vi.rate); - - this->si[stream_num]->factor = 90000; - this->si[stream_num]->quotient = vi.rate; - - if (vi.bitrate_nominal<1) - this->avg_bitrate += 100000; /* assume 100 kbit */ - else - this->avg_bitrate += vi.bitrate_nominal; - - } else { - this->si[stream_num]->factor = 900; - this->si[stream_num]->quotient = 441; - - this->si[stream_num]->headers = 0; - xine_log (this->stream->xine, XINE_LOG_MSG, - _("ogg: vorbis audio track indicated but no vorbis stream header found.\n")); - } - vorbis_comment_clear(&vc); - vorbis_info_clear(&vi); -} - -static void decode_speex_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { -#ifdef HAVE_SPEEX - void *st; - SpeexMode *mode; - SpeexHeader *header; - - this->si[stream_num]->buf_types = BUF_AUDIO_SPEEX - +this->num_audio_streams++; - - this->si[stream_num]->headers = 1; - - header = speex_packet_to_header (op->packet, op->bytes); - - if (header) { - int bitrate; - mode = (SpeexMode *) speex_mode_list[header->mode]; - - st = speex_decoder_init (mode); - - speex_decoder_ctl (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->si[stream_num]->factor = 90000; - this->si[stream_num]->quotient = header->rate; - - this->avg_bitrate += bitrate; - - lprintf ("detected Speex stream,\trate %d\tbitrate %d\n", header->rate, bitrate); - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, header->rate); - this->si[stream_num]->headers += header->extra_headers; - } -#else - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Speex stream detected, unable to play\n"); - - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; -#endif -} - -static void decode_video_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - buf_element_t *buf; - xine_bmiheader bih; - int channel; - - int16_t locbits_per_sample; - uint32_t locsubtype; - int32_t locsize, locdefault_len, locbuffersize, locwidth, locheight; - int64_t loctime_unit, locsamples_per_unit; - - /* read fourcc with machine endianness */ - locsubtype = *((uint32_t *)&op->packet[9]); - - /* everything else little endian */ - locsize = _X_LE_32(&op->packet[13]); - loctime_unit = _X_LE_64(&op->packet[17]); - locsamples_per_unit = _X_LE_64(&op->packet[25]); - locdefault_len = _X_LE_32(&op->packet[33]); - locbuffersize = _X_LE_32(&op->packet[37]); - locbits_per_sample = _X_LE_16(&op->packet[41]); - locwidth = _X_LE_32(&op->packet[45]); - locheight = _X_LE_32(&op->packet[49]); - - lprintf ("direct show filter created stream detected, hexdump:\n"); -#ifdef LOG - xine_hexdump (op->packet, op->bytes); -#endif - - channel = this->num_video_streams++; - - this->si[stream_num]->buf_types = _x_fourcc_to_buf_video (locsubtype); - if( !this->si[stream_num]->buf_types ) - this->si[stream_num]->buf_types = BUF_VIDEO_UNKNOWN; - this->si[stream_num]->buf_types |= channel; - this->si[stream_num]->headers = 0; /* header is sent below */ - - lprintf ("subtype %.4s\n", (char*)&locsubtype); - lprintf ("time_unit %" PRId64 "\n", loctime_unit); - lprintf ("samples_per_unit %" PRId64 "\n", locsamples_per_unit); - lprintf ("default_len %d\n", locdefault_len); - lprintf ("buffersize %d\n", locbuffersize); - lprintf ("bits_per_sample %d\n", locbits_per_sample); - lprintf ("width %d\n", locwidth); - lprintf ("height %d\n", locheight); - lprintf ("buf_type %08x\n",this->si[stream_num]->buf_types); - - bih.biSize=sizeof(xine_bmiheader); - bih.biWidth = locwidth; - bih.biHeight= locheight; - bih.biPlanes= 0; - memcpy(&bih.biCompression, &locsubtype, 4); - bih.biBitCount= 0; - bih.biSizeImage=locwidth*locheight; - bih.biXPelsPerMeter=1; - bih.biYPelsPerMeter=1; - bih.biClrUsed=0; - bih.biClrImportant=0; - - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAMERATE| - BUF_FLAG_FRAME_END; - this->frame_duration = loctime_unit * 9 / 1000; - this->si[stream_num]->factor = loctime_unit * 9; - this->si[stream_num]->quotient = 1000; - buf->decoder_info[0] = this->frame_duration; - memcpy (buf->content, &bih, sizeof (xine_bmiheader)); - buf->size = sizeof (xine_bmiheader); - buf->type = this->si[stream_num]->buf_types; - - /* video metadata */ - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_FOURCC, locsubtype); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, locwidth); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, locheight); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->frame_duration); - - this->avg_bitrate += 500000; /* FIXME */ - - this->video_fifo->put (this->video_fifo, buf); -} - -static void decode_audio_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - - if (this->audio_fifo) { - buf_element_t *buf; - int codec; - char str[5]; - int channel; - - int16_t locbits_per_sample, locchannels, locblockalign; - int32_t locsize, locdefault_len, locbuffersize, locavgbytespersec; - int64_t loctime_unit, locsamples_per_unit; - - locsize = _X_LE_32(&op->packet[13]); - loctime_unit = _X_LE_64(&op->packet[17]); - locsamples_per_unit = _X_LE_64(&op->packet[25]); - locdefault_len = _X_LE_32(&op->packet[33]); - locbuffersize = _X_LE_32(&op->packet[37]); - locbits_per_sample = _X_LE_16(&op->packet[41]); - locchannels = _X_LE_16(&op->packet[45]); - locblockalign = _X_LE_16(&op->packet[47]); - locavgbytespersec= _X_LE_32(&op->packet[49]); - - lprintf ("direct show filter created audio stream detected, hexdump:\n"); -#ifdef LOG - xine_hexdump (op->packet, op->bytes); -#endif - - memcpy(str, &op->packet[9], 4); - str[4] = 0; - codec = strtoul(str, NULL, 16); - - channel= this->num_audio_streams++; - - this->si[stream_num]->buf_types = _x_formattag_to_buf_audio(codec); - if( this->si[stream_num]->buf_types ) { - this->si[stream_num]->buf_types |= channel; - } else { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_ogg: unknown audio codec type 0x%x\n", codec); - this->si[stream_num]->buf_types = BUF_AUDIO_UNKNOWN; - /*break;*/ - } - - lprintf ("subtype 0x%x\n", codec); - lprintf ("time_unit %" PRId64 "\n", loctime_unit); - lprintf ("samples_per_unit %" PRId64 "\n", locsamples_per_unit); - lprintf ("default_len %d\n", locdefault_len); - lprintf ("buffersize %d\n", locbuffersize); - lprintf ("bits_per_sample %d\n", locbits_per_sample); - lprintf ("channels %d\n", locchannels); - lprintf ("blockalign %d\n", locblockalign); - lprintf ("avgbytespersec %d\n", locavgbytespersec); - lprintf ("buf_type %08x\n",this->si[stream_num]->buf_types); - - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); - buf->type = this->si[stream_num]->buf_types; - buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; - buf->decoder_info[0] = 0; - buf->decoder_info[1] = locsamples_per_unit; - buf->decoder_info[2] = locbits_per_sample; - buf->decoder_info[3] = locchannels; - this->audio_fifo->put (this->audio_fifo, buf); - - this->si[stream_num]->headers = 0; /* header already sent */ - this->si[stream_num]->factor = 90000; - this->si[stream_num]->quotient = locsamples_per_unit; - - this->avg_bitrate += locavgbytespersec*8; - - /* audio metadata */ - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC, codec); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, locchannels); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, locbits_per_sample); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, locsamples_per_unit); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, locavgbytespersec * 8); - - } else /* no audio_fifo there */ - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; -} - -static void decode_dshow_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - - lprintf ("older Direct Show filter-generated stream header detected. Hexdump:\n"); -#ifdef LOG - xine_hexdump (op->packet, op->bytes); -#endif - - this->si[stream_num]->headers = 0; /* header is sent below */ - - if ( (_X_LE_32(&op->packet[96]) == 0x05589f80) && (op->bytes >= 184)) { - - buf_element_t *buf; - xine_bmiheader bih; - int channel; - uint32_t fcc; - - lprintf ("seems to be a video stream.\n"); - - channel = this->num_video_streams++; - fcc = *(uint32_t*)(op->packet+68); - lprintf ("fourcc %08x\n", fcc); - - this->si[stream_num]->buf_types = _x_fourcc_to_buf_video (fcc); - if( !this->si[stream_num]->buf_types ) - this->si[stream_num]->buf_types = BUF_VIDEO_UNKNOWN; - this->si[stream_num]->buf_types |= channel; - - bih.biSize = sizeof(xine_bmiheader); - bih.biWidth = _X_LE_32(&op->packet[176]); - bih.biHeight = _X_LE_32(&op->packet[180]); - bih.biPlanes = 0; - memcpy (&bih.biCompression, op->packet+68, 4); - bih.biBitCount = _X_LE_16(&op->packet[182]); - if (!bih.biBitCount) - bih.biBitCount = 24; /* FIXME ? */ - bih.biSizeImage = (bih.biBitCount>>3)*bih.biWidth*bih.biHeight; - bih.biXPelsPerMeter = 1; - bih.biYPelsPerMeter = 1; - bih.biClrUsed = 0; - bih.biClrImportant = 0; - - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAMERATE| - BUF_FLAG_FRAME_END; - this->frame_duration = (*(int64_t*)(op->packet+164)) * 9 / 1000; - this->si[stream_num]->factor = (*(int64_t*)(op->packet+164)) * 9; - this->si[stream_num]->quotient = 1000; - - buf->decoder_info[0] = this->frame_duration; - memcpy (buf->content, &bih, sizeof (xine_bmiheader)); - buf->size = sizeof (xine_bmiheader); - buf->type = this->si[stream_num]->buf_types; - this->video_fifo->put (this->video_fifo, buf); - - lprintf ("subtype %.4s\n", (char*)&fcc); - lprintf ("buf_type %08x\n", this->si[stream_num]->buf_types); - lprintf ("video size %d x %d\n", bih.biWidth, bih.biHeight); - lprintf ("frame duration %d\n", this->frame_duration); - - /* video metadata */ - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, bih.biWidth); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, bih.biHeight); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->frame_duration); - - this->avg_bitrate += 500000; /* FIXME */ - - this->ignore_keyframes = 1; - - } else if (_X_LE_32(&op->packet[96]) == 0x05589F81) { - -#if 0 - /* FIXME: no test streams */ - - buf_element_t *buf; - int codec; - char str[5]; - int channel; - int extra_size; - - extra_size = *(int16_t*)(op->packet+140); - format = *(int16_t*)(op->packet+124); - channels = *(int16_t*)(op->packet+126); - samplerate = *(int32_t*)(op->packet+128); - nAvgBytesPerSec = *(int32_t*)(op->packet+132); - nBlockAlign = *(int16_t*)(op->packet+136); - wBitsPerSample = *(int16_t*)(op->packet+138); - samplesize = (sh_a->wf->wBitsPerSample+7)/8; - cbSize = extra_size; - if(extra_size > 0) - memcpy(wf+sizeof(WAVEFORMATEX),op->packet+142,extra_size); -#endif - - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "FIXME, old audio format not handled\n"); - - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; - - } else { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "old header detected but stream type is unknown\n"); - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; - } -} - -static void decode_text_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - int channel=0; - uint32_t *val; - buf_element_t *buf; - - lprintf ("textstream detected.\n"); - this->si[stream_num]->headers = 2; - channel = this->num_spu_streams++; - this->si[stream_num]->buf_types = BUF_SPU_OGM | channel; - - /*send an empty spu to inform the video_decoder, that there is a stream*/ - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); - buf->type = this->si[stream_num]->buf_types; - buf->pts = 0; - val = (uint32_t * )buf->content; - *val++=0; - *val++=0; - *val++=0; - this->video_fifo->put (this->video_fifo, buf); -} - -static void decode_theora_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - -#ifdef HAVE_THEORA - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_ogg: Theorastreamsupport is highly alpha at the moment\n"); - - if (theora_decode_header(&this->t_info, &this->t_comment, op) >= 0) { - - this->num_video_streams++; - - this->si[stream_num]->factor = (int64_t) 90000 * (int64_t) this->t_info.fps_denominator; - - if (!this->t_info.fps_numerator) { - this->t_info.fps_numerator = 1; /* FIXME: default value ? */ - } - this->si[stream_num]->quotient = this->t_info.fps_numerator; - - this->frame_duration = ((int64_t) 90000*this->t_info.fps_denominator); - this->frame_duration /= this->t_info.fps_numerator; - - this->si[stream_num]->granuleshift = intlog(this->t_info.keyframe_frequency_force-1); - - this->si[stream_num]->headers=3; - this->si[stream_num]->buf_types = BUF_VIDEO_THEORA; - - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "theora"); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->t_info.frame_width); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->t_info.frame_height); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->frame_duration); - - /*currently aspect_nominator and -denumerator are 0?*/ - if (this->t_info.aspect_denominator) { - int64_t ratio = ((int64_t) this->t_info.aspect_numerator * 10000); - - ratio /= this->t_info.aspect_denominator; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, ratio); - } - - lprintf ("decoded theora header \n"); - lprintf ("frameduration %d\n",this->frame_duration); - lprintf ("w:%d h:%d \n",this->t_info.frame_width,this->t_info.frame_height); - lprintf ("an:%d ad:%d \n",this->t_info.aspect_numerator,this->t_info.aspect_denominator); - } else { - /*Rejected stream*/ - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "A theora header was rejected by libtheora\n"); - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; - this->si[stream_num]->headers = 0; /* FIXME: don't know */ - } -#else - this->si[stream_num]->buf_types = BUF_VIDEO_THEORA; - this->num_video_streams++; - this->unhandled_video_streams++; - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "theora"); -#endif -} - -static void decode_flac_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - xine_flac_metadata_header header; - xine_flac_streaminfo_block streaminfo; - buf_element_t *buf; - xine_waveformatex wave; - - /* Packet type */ - _x_assert(op->packet[0] == 0x7F); - - /* OggFLAC signature */ - _x_assert(op->packet[1] == 'F'); _x_assert(op->packet[2] == 'L'); - _x_assert(op->packet[3] == 'A'); _x_assert(op->packet[4] == 'C'); - - /* Version: supported only 1.0 */ - _x_assert(op->packet[5] == 1); _x_assert(op->packet[6] == 0); - - /* Header count */ - this->si[stream_num]->headers = 0/*_X_BE_16(&op->packet[7]) +1*/; - - /* fLaC signature */ - _x_assert(op->packet[9] == 'f'); _x_assert(op->packet[10] == 'L'); - _x_assert(op->packet[11] == 'a'); _x_assert(op->packet[12] == 'C'); - - _x_parse_flac_metadata_header(&op->packet[13], &header); - - switch ( header.blocktype ) { - case FLAC_BLOCKTYPE_STREAMINFO: - _x_assert(header.length == FLAC_STREAMINFO_SIZE); - _x_parse_flac_streaminfo_block(&op->packet[17], &streaminfo); - break; - } - - this->si[stream_num]->buf_types = BUF_AUDIO_FLAC - +this->num_audio_streams++; - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, streaminfo.samplerate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, streaminfo.channels); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, streaminfo.bits_per_sample); - - this->si[stream_num]->factor = 90000; - - 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] = streaminfo.samplerate; - buf->decoder_info[2] = streaminfo.bits_per_sample; - buf->decoder_info[3] = streaminfo.channels; - buf->size = sizeof(xine_waveformatex) + FLAC_STREAMINFO_SIZE; - memcpy(buf->content+sizeof(xine_waveformatex), &op->packet[17], FLAC_STREAMINFO_SIZE); - xine_hexdump(&op->packet[17], FLAC_STREAMINFO_SIZE); - wave.cbSize = FLAC_STREAMINFO_SIZE; - memcpy(buf->content, &wave, sizeof(xine_waveformatex)); - - this->audio_fifo->put(this->audio_fifo, buf); - - /* Skip the Ogg framing info */ - op->bytes -= 9; - op->packet += 9; -} - -static void decode_annodex_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - lprintf ("Annodex stream detected\n"); - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; - this->si[stream_num]->headers = 1; - this->si[stream_num]->header_granulepos = op->granulepos; - _x_meta_info_set(this->stream, XINE_META_INFO_SYSTEMLAYER, "Annodex"); -} - -static void decode_anxdata_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - int64_t granule_rate_n, granule_rate_d; - uint32_t secondary_headers; - char content_type[1024]; - int content_type_length; - - lprintf("AnxData stream detected\n"); - - /* read granule rate */ - granule_rate_n = _X_LE_64(&op->packet[8]); - granule_rate_d = _X_LE_64(&op->packet[16]); - secondary_headers = _X_LE_32(&op->packet[24]); - - lprintf("granule_rate %" PRId64 "/%" PRId64 ", %d secondary headers\n", - granule_rate_n, granule_rate_d, secondary_headers); - - /* read "Content-Tyoe" MIME header */ - sscanf(&op->packet[28], "Content-Type: %1023s\r\n", content_type); - content_type_length = strlen(content_type); - - lprintf("Content-Type: %s (length:%d)\n", content_type, content_type_length); - - /* how many header packets in the AnxData stream? */ - this->si[stream_num]->headers = secondary_headers + 1; - this->si[stream_num]->hide_first_header = 1; - - /* set factor and quotient */ - this->si[stream_num]->factor = (int64_t) 90000 * granule_rate_d; - this->si[stream_num]->quotient = granule_rate_n; - - lprintf("factor: %" PRId64 ", quotient: %" PRId64 "\n", - this->si[stream_num]->factor, this->si[stream_num]->quotient); - - /* what type of stream are we dealing with? */ - if (!strncmp(content_type, "audio/x-vorbis", content_type_length)) { - this->si[stream_num]->buf_types = BUF_AUDIO_VORBIS; - this->num_audio_streams++; - } else if (!strncmp(content_type, "audio/x-speex", content_type_length)) { - this->num_audio_streams++; -#ifdef HAVE_SPEEX - this->si[stream_num]->buf_types = BUF_AUDIO_SPEEX; -#else - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; -#endif - } else if (!strncmp(content_type, "video/x-theora", content_type_length)) { - this->num_video_streams++; -#ifdef HAVE_THEORA - this->si[stream_num]->buf_types = BUF_VIDEO_THEORA; -#else - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; -#endif - } else if (!strncmp(content_type, "text/x-cmml", content_type_length)) { - unsigned int channel = this->num_spu_streams++; - this->si[stream_num]->headers = 0; - this->si[stream_num]->buf_types = BUF_SPU_CMML | channel; - this->si[stream_num]->granuleshift = 0; - } else { - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; - } - -} - -static void decode_cmml_header (demux_ogg_t *this, const int stream_num, ogg_packet *op) { - unsigned int channel = this->num_spu_streams++; - this->si[stream_num]->headers = 0; - this->si[stream_num]->buf_types = BUF_SPU_CMML | channel; - - this->si[stream_num]->factor = 90000 * _X_LE_64(&op->packet[20]); - this->si[stream_num]->quotient = _X_LE_64(&op->packet[12]); - this->si[stream_num]->granuleshift = (int)op->packet[28]; -} - -/* - * interpret stream start packages, send headers - */ -static void send_header (demux_ogg_t *this) { - - int stream_num = -1; - int cur_serno; - int done = 0; - ogg_packet op; - xine_event_t ui_event; - - lprintf ("detecting stream types...\n"); - - this->ignore_keyframes = 0; - - while (!done) { - if (!read_ogg_packet(this)) { - this->status = DEMUX_FINISHED; - return; - } - /* now we've got at least one new page */ - - cur_serno = ogg_page_serialno (&this->og); - - if (ogg_page_bos(&this->og)) { - lprintf ("beginning of stream\n"); - lprintf ("serial number %d\n", cur_serno); - - if( this->num_streams == MAX_STREAMS ) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, "demux_ogg: MAX_STREAMS exceeded, aborting.\n"); - this->status = DEMUX_FINISHED; - return; - } - stream_num = new_stream_info(this, cur_serno); - - } else { - stream_num = get_stream(this, cur_serno); - if (stream_num == -1) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, "demux_ogg: stream with no beginning!\n"); - this->status = DEMUX_FINISHED; - return; - } - } - - ogg_stream_pagein(&this->si[stream_num]->oss, &this->og); - - while (ogg_stream_packetout(&this->si[stream_num]->oss, &op) == 1) { - - if (!this->si[stream_num]->buf_types) { - - /* detect buftype */ - if (!strncmp (&op.packet[1], "vorbis", 6)) { - decode_vorbis_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[0], "Speex", 5)) { - decode_speex_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[1], "video", 5)) { - decode_video_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[1], "audio", 5)) { - decode_audio_header(this, stream_num, &op); - } else if (op.bytes >= 142 - && !strncmp (&op.packet[1], "Direct Show Samples embedded in Ogg", 35) ) { - decode_dshow_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[1], "text", 4)) { - decode_text_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[1], "theora", 6)) { - decode_theora_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[1], "FLAC", 4)) { - decode_flac_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[0], "Annodex", 7)) { - decode_annodex_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[0], "AnxData", 7)) { - decode_anxdata_header(this, stream_num, &op); - } else if (!strncmp (&op.packet[0], "CMML", 4)) { - decode_cmml_header(this, stream_num, &op); - } else { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_ogg: unknown stream type (signature >%.8s<). hex dump of bos packet follows:\n", - op.packet); - if(this->stream->xine->verbosity >= XINE_VERBOSITY_DEBUG) - xine_hexdump (op.packet, op.bytes); - - this->si[stream_num]->buf_types = BUF_CONTROL_NOP; - } - } - - /* send preview buffer */ - if (this->si[stream_num]->headers > 0 || - op.packet[0] == PACKET_TYPE_COMMENT) { - if (this->si[stream_num]->hide_first_header) - this->si[stream_num]->hide_first_header = 0; - else { - lprintf ("sending preview buffer of stream type %08x\n", - this->si[stream_num]->buf_types); - - send_ogg_buf (this, &op, stream_num, BUF_FLAG_HEADER); - this->si[stream_num]->headers --; - } - } - - /* are we finished ? */ - if (!ogg_page_bos(&this->og)) { - int i; - done = 1; - - for (i=0; i<this->num_streams; i++) { - if (this->si[i]->headers > 0) - done = 0; - - llprintf(DEBUG_PREVIEWS, - "%d preview buffers left to send from stream %d\n", - this->si[i]->headers, i); - } - } - } - } - - ui_event.type = XINE_EVENT_UI_CHANNELS_CHANGED; - ui_event.data_length = 0; - xine_event_send(this->stream, &ui_event); - - /*get the streamlength*/ - get_stream_length (this); - -} - -static int demux_ogg_send_chunk (demux_plugin_t *this_gen) { - demux_ogg_t *this = (demux_ogg_t *) this_gen; - - int stream_num; - int cur_serno; - - ogg_packet op; - - ogg_handle_event(this); - - llprintf(DEBUG_PACKETS, "send package...\n"); - - if (!read_ogg_packet(this)) { - this->status = DEMUX_FINISHED; - lprintf ("EOF\n"); - return this->status; - } - - /* now we've got one new page */ - - cur_serno = ogg_page_serialno (&this->og); - stream_num = get_stream(this, cur_serno); - if (stream_num < 0) { - lprintf ("error: unknown stream, serialnumber %d\n", cur_serno); - - if (!ogg_page_bos(&this->og)) { - lprintf ("help, stream with no beginning!\n"); - } - lprintf ("adding late stream with serial number %d (all content will be discarded)\n", cur_serno); - - if( this->num_streams == MAX_STREAMS ) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, "demux_ogg: MAX_STREAMS exceeded, aborting.\n"); - this->status = DEMUX_FINISHED; - return this->status; - } - stream_num = new_stream_info(this, cur_serno); - } - - ogg_stream_pagein(&this->si[stream_num]->oss, &this->og); - - if (ogg_page_bos(&this->og)) { - lprintf ("beginning of stream: serial number %d - discard\n", - ogg_page_serialno (&this->og)); - while (ogg_stream_packetout(&this->si[stream_num]->oss, &op) == 1) ; - return this->status; - } - - /*while keyframeseeking only process videostream*/ - if (!this->ignore_keyframes && this->keyframe_needed - && ((this->si[stream_num]->buf_types & 0xFF000000) != BUF_VIDEO_BASE)) - return this->status; - - while (ogg_stream_packetout(&this->si[stream_num]->oss, &op) == 1) { - /* printf("demux_ogg: packet: %.8s\n", op.packet); */ - /* printf("demux_ogg: got a packet\n"); */ - - if ((*op.packet & PACKET_TYPE_HEADER) && - (this->si[stream_num]->buf_types!=BUF_VIDEO_THEORA) && (this->si[stream_num]->buf_types!=BUF_AUDIO_SPEEX) && (this->si[stream_num]->buf_types!=BUF_AUDIO_FLAC)) { - if (op.granulepos != -1) { - this->si[stream_num]->header_granulepos = op.granulepos; - lprintf ("header with granulepos, remembering granulepos\n"); - } else { - lprintf ("header => discard\n"); - } - continue; - } - - /*discard granulepos-less packets and to early audiopackets*/ - if (this->si[stream_num]->resync) { - if ((this->si[stream_num]->buf_types & 0xFF000000) == BUF_SPU_BASE) { - /*never drop subtitles*/ - this->si[stream_num]->resync=0; - } else if ((op.granulepos == -1) && (this->si[stream_num]->header_granulepos == -1)) { - continue; - } else { - - /*dump too early packets*/ - if ((get_pts(this,stream_num,op.granulepos)-this->start_pts) > -90000) - this->si[stream_num]->resync=0; - else - continue; - } - } - - if (!this->ignore_keyframes && this->keyframe_needed) { - lprintf ("keyframe needed... buf_type=%08x\n", this->si[stream_num]->buf_types); - if (this->si[stream_num]->buf_types == BUF_VIDEO_THEORA) { -#ifdef HAVE_THEORA - - int keyframe_granule_shift; - int64_t pframe=-1,iframe=-1; - - keyframe_granule_shift = this->si[stream_num]->granuleshift; - - if(op.granulepos>=0){ - iframe=op.granulepos>>keyframe_granule_shift; - pframe=op.granulepos-(iframe<<keyframe_granule_shift); - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "seeking keyframe i %" PRId64 " p %" PRId64 "\n", iframe, pframe); - if (pframe!=0) - continue; - } else - continue; - this->keyframe_needed = 0; - this->start_pts=get_pts(this,stream_num,op.granulepos); -#endif - } else if ((this->si[stream_num]->buf_types & 0xFF000000) == BUF_VIDEO_BASE) { - - /*calculate the current pts*/ - if (op.granulepos!=-1) { - this->start_pts=get_pts(this, stream_num, op.granulepos); - } else if (this->start_pts!=-1) - this->start_pts=this->start_pts+this->frame_duration; - - /*seek the keyframe*/ - if ((*op.packet == PACKET_IS_SYNCPOINT) && (this->start_pts!=-1)) - this->keyframe_needed = 0; - else - continue; - - } else if ((this->si[stream_num]->buf_types & 0xFF000000) == BUF_VIDEO_BASE) continue; - } - send_ogg_buf (this, &op, stream_num, 0); - - /*delete used header_granulepos*/ - if (op.granulepos == -1) - this->si[stream_num]->header_granulepos = -1; - - } - if (ogg_page_eos(&this->og)) { - int i; - int finished_streams = 0; - - lprintf("end of stream, serialnumber %d\n", cur_serno); - this->si[stream_num]->delivered_eos = 1; - - /* check if all logical streams are finished */ - for (i = 0; i < this->num_streams; i++) { - finished_streams += this->si[i]->delivered_eos; - } - - /* if all streams are finished, perhaps a chained stream follows */ - if (finished_streams == this->num_streams) { - /* delete current logical streams */ - for (i = 0; i < this->num_streams; i++) { - ogg_stream_clear(&this->si[i]->oss); - if (this->si[i]->language) { - free (this->si[i]->language); - } - free (this->si[i]); - } - this->num_streams = 0; - this->num_audio_streams = 0; - this->num_video_streams = 0; - this->unhandled_video_streams = 0; - this->num_spu_streams = 0; - this->avg_bitrate = 1; - - /* try to read a chained stream */ - this->send_newpts = 1; - this->last_pts[0] = 0; - this->last_pts[1] = 0; - - /* send control buffer to avoid buffer leak */ - _x_demux_control_end(this->stream, 0); - _x_demux_control_start(this->stream); - send_header(this); - } - } - - return this->status; -} - -static void demux_ogg_dispose (demux_plugin_t *this_gen) { - demux_ogg_t *this = (demux_ogg_t *) this_gen; - int i; - - for (i=0; i<this->num_streams; i++) { - ogg_stream_clear(&this->si[i]->oss); - - if (this->si[i]->language) { - free (this->si[i]->language); - } - free(this->si[i]); - } - - ogg_sync_clear(&this->oy); - -#ifdef HAVE_THEORA - theora_comment_clear (&this->t_comment); - theora_info_clear (&this->t_info); -#endif - - if (this->chapter_info){ - free (this->chapter_info->entries); - free (this->chapter_info); - } - if (this->title){ - free (this->title); - } - if (this->event_queue) - xine_event_dispose_queue (this->event_queue); - - free (this); -} - -static int demux_ogg_get_status (demux_plugin_t *this_gen) { - demux_ogg_t *this = (demux_ogg_t *) this_gen; - - return this->status; -} - -static void demux_ogg_send_headers (demux_plugin_t *this_gen) { - demux_ogg_t *this = (demux_ogg_t *) this_gen; - - this->video_fifo = this->stream->video_fifo; - this->audio_fifo = this->stream->audio_fifo; - - this->status = DEMUX_OK; - - /* - * send start buffers - */ - - this->last_pts[0] = 0; - this->last_pts[1] = 0; - - /* - * initialize ogg engine - */ - ogg_sync_init(&this->oy); - - this->num_streams = 0; - this->num_audio_streams = 0; - this->num_video_streams = 0; - this->num_spu_streams = 0; - this->avg_bitrate = 1; - - this->input->seek (this->input, 0, SEEK_SET); - - if (this->status == DEMUX_OK) { - _x_demux_control_start(this->stream); - send_header (this); - lprintf ("headers sent, avg bitrate is %" PRId64 "\n", this->avg_bitrate); - } - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, - this->num_video_streams > 0); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, - this->num_video_streams > this->unhandled_video_streams); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, - this->num_audio_streams > 0); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_MAX_SPU_CHANNEL, - this->num_spu_streams); -} - -static int demux_ogg_seek (demux_plugin_t *this_gen, - off_t start_pos, int start_time, int playing) { - - demux_ogg_t *this = (demux_ogg_t *) this_gen; - int i; - start_time /= 1000; - start_pos = (off_t) ( (double) start_pos / 65535 * - this->input->get_length (this->input) ); - /* - * seek to start position - */ - - if (INPUT_IS_SEEKABLE(this->input)) { - - this->keyframe_needed = (this->num_video_streams>0); - - if ( (!start_pos) && (start_time)) { - if (this->time_length != -1) { - /*do the seek via time*/ - int current_time=-1; - off_t current_pos; - current_pos=this->input->get_current_pos(this->input); - - /*try to find out the current time*/ - if (this->last_pts[PTS_VIDEO]) { - current_time=this->last_pts[PTS_VIDEO]/90000; - } else if (this->last_pts[PTS_AUDIO]) { - current_time=this->last_pts[PTS_AUDIO]/90000; - } - - /*fixme, the file could grow, do something - about this->time_length using get_lenght to verify, that the stream - hasn` changed its length, otherwise no seek to "new" data is possible*/ - - lprintf ("seek to time %d called\n",start_time); - lprintf ("current time is %d\n",current_time); - - if (current_time > start_time) { - /*seek between beginning and current_pos*/ - - /*fixme - sometimes we seek backwards and during - keyframeseeking, we undo the seek*/ - - start_pos = start_time * current_pos - / current_time ; - } else { - /*seek between current_pos and end*/ - start_pos = current_pos + - ((start_time - current_time) * - ( this->input->get_length(this->input) - current_pos ) / - ( (this->time_length / 1000) - current_time) - ); - } - - lprintf ("current_pos is %" PRId64 "\n",current_pos); - lprintf ("new_pos is %" PRId64 "\n",start_pos); - - } else { - /*seek using avg_bitrate*/ - start_pos = start_time * this->avg_bitrate/8; - } - - lprintf ("seeking to %d seconds => %" PRId64 " bytes\n", - start_time, start_pos); - - } - - ogg_sync_reset(&this->oy); - - for (i=0; i<this->num_streams; i++) { - this->si[i]->header_granulepos = -1; - ogg_stream_reset(&this->si[i]->oss); - } - - /*some strange streams have no syncpoint flag set at the beginning*/ - if (start_pos == 0) - this->keyframe_needed = 0; - - lprintf ("seek to %" PRId64 " called\n",start_pos); - - this->input->seek (this->input, start_pos, SEEK_SET); - - } - - /* fixme - this would be a nice position to do the following tasks - 1. adjust an ogg videostream to a keyframe - 2. compare the keyframe_pts with start_time. if the difference is to - high (e.g. larger than max keyframe_intervall, do a new seek or - continue reading - 3. adjust the audiostreams in such a way, that the - difference is not to high. - - In short words, do all the cleanups necessary to continue playback - without further actions - */ - - this->send_newpts = 1; - this->status = DEMUX_OK; - - if( !playing ) { - - this->buf_flag_seek = 0; - - } else { - if (start_pos!=0) { - this->buf_flag_seek = 1; - /*each stream has to continue with a packet that has an - granulepos*/ - for (i=0; i<this->num_streams; i++) { - this->si[i]->resync = 1; - } - - this->start_pts=-1; - } - - _x_demux_flush_engine(this->stream); - } - - return this->status; -} - -static int demux_ogg_get_stream_length (demux_plugin_t *this_gen) { - - demux_ogg_t *this = (demux_ogg_t *) this_gen; - - if (this->time_length==-1){ - if (this->avg_bitrate) { - return (int)((int64_t)1000 * this->input->get_length (this->input) * 8 / - this->avg_bitrate); - } else { - return 0; - } - } else { - return this->time_length; - } -} - -static uint32_t demux_ogg_get_capabilities(demux_plugin_t *this_gen) { - demux_ogg_t *this = (demux_ogg_t *) this_gen; - int cap_chapter = 0; - - if (this->chapter_info) - cap_chapter = DEMUX_CAP_CHAPTERS; - - return DEMUX_CAP_SPULANG | DEMUX_CAP_AUDIOLANG | cap_chapter; -} - -static int format_lang_string (demux_ogg_t * this, uint32_t buf_mask, uint32_t buf_type, int channel, char *str) { - int stream_num; - - for (stream_num=0; stream_num<this->num_streams; stream_num++) { - if ((this->si[stream_num]->buf_types & buf_mask) == buf_type) { - if (this->si[stream_num]->language) { - if (snprintf (str, XINE_LANG_MAX, "%s", this->si[stream_num]->language) >= XINE_LANG_MAX) - /* the string got truncated */ - str[XINE_LANG_MAX - 2] = str[XINE_LANG_MAX - 3] = str[XINE_LANG_MAX - 4] = '.'; - /* TODO: provide long version in XINE_META_INFO_FULL_LANG */ - } else { - snprintf(str, XINE_LANG_MAX, "channel %d",channel); - } - return DEMUX_OPTIONAL_SUCCESS; - } - } - return DEMUX_OPTIONAL_UNSUPPORTED; -} - -static int demux_ogg_get_optional_data(demux_plugin_t *this_gen, - void *data, int data_type) { - - demux_ogg_t *this = (demux_ogg_t *) this_gen; - - char *str=(char *) data; - int channel = *((int *)data); - - switch (data_type) { - case DEMUX_OPTIONAL_DATA_SPULANG: - lprintf ("DEMUX_OPTIONAL_DATA_SPULANG channel = %d\n",channel); - if (channel==-1) { - strcpy( str, "none"); - return DEMUX_OPTIONAL_SUCCESS; - } else if ((channel>=0) && (channel<this->num_streams)) { - return format_lang_string (this, 0xFFFFFFFF, BUF_SPU_OGM+channel, channel, str); - } - return DEMUX_OPTIONAL_UNSUPPORTED; - case DEMUX_OPTIONAL_DATA_AUDIOLANG: - lprintf ("DEMUX_OPTIONAL_DATA_AUDIOLANG channel = %d\n",channel); - if (channel==-1) { - return format_lang_string (this, 0xFF00001F, BUF_AUDIO_BASE, channel, str); - } else if ((channel>=0) && (channel<this->num_streams)) { - return format_lang_string (this, 0xFF00001F, BUF_AUDIO_BASE+channel, channel, str); - } - return DEMUX_OPTIONAL_UNSUPPORTED; - default: - return DEMUX_OPTIONAL_UNSUPPORTED; - } -} - -static int detect_ogg_content (int detection_method, demux_class_t *class_gen, - input_plugin_t *input) { - - switch (detection_method) { - - case METHOD_BY_CONTENT: { - uint8_t buf[4]; - - if (_x_demux_read_header(input, buf, 4) != 4) - return 0; - - if ((buf[0] == 'O') && (buf[1] == 'g') && (buf[2] == 'g') && - (buf[3] == 'S')) - return 1; - else - return 0; - } - - case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); - - if (_x_demux_check_extension (mrl, extensions)) - return 1; - else - return 0; - } - - case METHOD_EXPLICIT: - return 1; - - default: - return 0; - } -} - -static int detect_anx_content (int detection_method, demux_class_t *class_gen, - input_plugin_t *input) { - - if (detect_ogg_content(detection_method, class_gen, input) == 0) - return 0; - - switch (detection_method) { - -#define ANNODEX_SIGNATURE_SEARCH 128 - - case METHOD_BY_CONTENT: { - uint8_t buf[ANNODEX_SIGNATURE_SEARCH]; - int found_annodex_signature = 0; - const char *annodex_signature = "Annodex"; - int annodex_signature_length = 7; /* = strlen(annodex_signature) */ - int i, j; - - if (_x_demux_read_header(input, buf, ANNODEX_SIGNATURE_SEARCH) != - ANNODEX_SIGNATURE_SEARCH) - return 0; - - /* scan for 'Annodex' signature in the first 64 bytes */ - for (i = 0, j = 0; i < ANNODEX_SIGNATURE_SEARCH; i++) { - if (buf[i] == annodex_signature[j]) { - if (j >= annodex_signature_length) { - /* found signature */ - found_annodex_signature = 1; - break; - } else { - j++; - } - } - } - - if (found_annodex_signature) - return 1; - else - return 0; - } - -#undef ANNODEX_SIGNATURE_SEARCH - - case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); - - if (_x_demux_check_extension (mrl, extensions)) - return 1; - else - return 0; - } - - case METHOD_EXPLICIT: - return 1; - - default: - return 0; - } -} - -static demux_plugin_t *anx_open_plugin (demux_class_t *class_gen, - xine_stream_t *stream, - input_plugin_t *input) { - - demux_ogg_t *this; - - if (detect_anx_content(stream->content_detection_method, class_gen, input) == 0) - return NULL; - - /* - * if we reach this point, the input has been accepted. - */ - - this = xine_xmalloc (sizeof (demux_ogg_t)); - memset (this, 0, sizeof(demux_ogg_t)); - this->stream = stream; - this->input = input; - - /* the Annodex demuxer currently calls into exactly the same functions as - * the Ogg demuxer, which seems to make this function a bit redundant, but - * this design leaves us a bit more room to change an Annodex demuxer's - * behaviour in the future if necessary */ - this->demux_plugin.send_headers = demux_ogg_send_headers; - this->demux_plugin.send_chunk = demux_ogg_send_chunk; - this->demux_plugin.seek = demux_ogg_seek; - this->demux_plugin.dispose = demux_ogg_dispose; - this->demux_plugin.get_status = demux_ogg_get_status; - this->demux_plugin.get_stream_length = demux_ogg_get_stream_length; - this->demux_plugin.get_capabilities = demux_ogg_get_capabilities; - this->demux_plugin.get_optional_data = demux_ogg_get_optional_data; - this->demux_plugin.demux_class = class_gen; - - this->status = DEMUX_FINISHED; - -#ifdef HAVE_THEORA - theora_info_init (&this->t_info); - theora_comment_init (&this->t_comment); -#endif - - this->chapter_info = 0; - this->title = 0; - this->event_queue = xine_event_new_queue (this->stream); - - return &this->demux_plugin; -} - -static demux_plugin_t *ogg_open_plugin (demux_class_t *class_gen, - xine_stream_t *stream, - input_plugin_t *input) { - - demux_ogg_t *this; - - if (detect_ogg_content(stream->content_detection_method, class_gen, input) == 0) - return NULL; - - /* - * if we reach this point, the input has been accepted. - */ - - this = xine_xmalloc (sizeof (demux_ogg_t)); - memset (this, 0, sizeof(demux_ogg_t)); - this->stream = stream; - this->input = input; - - this->demux_plugin.send_headers = demux_ogg_send_headers; - this->demux_plugin.send_chunk = demux_ogg_send_chunk; - this->demux_plugin.seek = demux_ogg_seek; - this->demux_plugin.dispose = demux_ogg_dispose; - this->demux_plugin.get_status = demux_ogg_get_status; - this->demux_plugin.get_stream_length = demux_ogg_get_stream_length; - this->demux_plugin.get_capabilities = demux_ogg_get_capabilities; - this->demux_plugin.get_optional_data = demux_ogg_get_optional_data; - this->demux_plugin.demux_class = class_gen; - - this->status = DEMUX_FINISHED; - -#ifdef HAVE_THEORA - theora_info_init (&this->t_info); - theora_comment_init (&this->t_comment); -#endif - - this->chapter_info = 0; - this->title = 0; - this->event_queue = xine_event_new_queue (this->stream); - - return &this->demux_plugin; -} - -/* - * Annodex demuxer class - */ - -static const char *anx_get_description (demux_class_t *this_gen) { - return "Annodex demux plugin"; -} - -static const char *anx_get_identifier (demux_class_t *this_gen) { - return "Annodex"; -} - -static const char *anx_get_extensions (demux_class_t *this_gen) { - return "anx axa axv"; -} - -static const char *anx_get_mimetypes (demux_class_t *this_gen) { - return "application/x-annodex: ogg: Annodex media;"; -} - -static void anx_class_dispose (demux_class_t *this_gen) { - demux_anx_class_t *this = (demux_anx_class_t *) this_gen; - - free (this); -} - -static void *anx_init_class (xine_t *xine, void *data) { - demux_anx_class_t *this; - - this = xine_xmalloc (sizeof (demux_anx_class_t)); - - this->demux_class.open_plugin = anx_open_plugin; - this->demux_class.get_description = anx_get_description; - this->demux_class.get_identifier = anx_get_identifier; - this->demux_class.get_mimetypes = anx_get_mimetypes; - this->demux_class.get_extensions = anx_get_extensions; - this->demux_class.dispose = anx_class_dispose; - - return this; -} - -/* - * ogg demuxer class - */ - -static const char *ogg_get_description (demux_class_t *this_gen) { - return "OGG demux plugin"; -} - -static const char *ogg_get_identifier (demux_class_t *this_gen) { - return "OGG"; -} - -static const char *ogg_get_extensions (demux_class_t *this_gen) { - return "ogg ogm spx"; -} - -static const char *ogg_get_mimetypes (demux_class_t *this_gen) { - return "audio/x-ogg: ogg: OggVorbis Audio;" - "audio/x-speex: ogg: Speex Audio;" - "application/x-ogg: ogg: Ogg Stream;" - "application/ogg: ogg: Ogg Stream;"; -} - -static void ogg_class_dispose (demux_class_t *this_gen) { - demux_ogg_class_t *this = (demux_ogg_class_t *) this_gen; - - free (this); -} - -static void *ogg_init_class (xine_t *xine, void *data) { - demux_ogg_class_t *this; - - this = xine_xmalloc (sizeof (demux_ogg_class_t)); - - this->demux_class.open_plugin = ogg_open_plugin; - this->demux_class.get_description = ogg_get_description; - this->demux_class.get_identifier = ogg_get_identifier; - this->demux_class.get_mimetypes = ogg_get_mimetypes; - this->demux_class.get_extensions = ogg_get_extensions; - this->demux_class.dispose = ogg_class_dispose; - - return this; -} - -/* - * exported plugin catalog entry - */ -static const demuxer_info_t demux_info_anx = { - 20 /* priority */ -}; - -static const demuxer_info_t demux_info_ogg = { - 10 /* priority */ -}; - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_DEMUX, 26, "ogg", XINE_VERSION_CODE, &demux_info_ogg, ogg_init_class }, - { PLUGIN_DEMUX, 26, "anx", XINE_VERSION_CODE, &demux_info_anx, anx_init_class }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/demuxers/demux_playlist.c b/src/demuxers/demux_playlist.c new file mode 100644 index 000000000..bbe6998e6 --- /dev/null +++ b/src/demuxers/demux_playlist.c @@ -0,0 +1,746 @@ +/* + * Copyright (C) 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 + * + * + * Playlist parser/demuxer by + * Claudio Ciccani (klan@users.sourceforge.net) + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> + +#define LOG_MODULE "demux_playlist" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "xineutils.h" +#include "bswap.h" +#include "demux.h" + +typedef enum { + XINE_PLT_NONE = 0, + XINE_PLT_REF = ME_FOURCC('R','E','F',0), + XINE_PLT_M3U = ME_FOURCC('M','3','U',0), + XINE_PLT_RAM = ME_FOURCC('R','A','M',0), + XINE_PLT_PLS = ME_FOURCC('P','L','S',0), + XINE_PLT_ASX = ME_FOURCC('A','S','X',0), + XINE_PLT_SMI = ME_FOURCC('S','M','I',0), + XINE_PLT_QTL = ME_FOURCC('Q','T','L',0), + XINE_PLT_XSPF = ME_FOURCC('X','S','P',0), + XINE_PLT_RSS = ME_FOURCC('R','S','S',0) +} playlist_t; + +typedef struct { + demux_plugin_t demux_plugin; + + xine_t *xine; + xine_stream_t *stream; + input_plugin_t *input; + + playlist_t playlist; + + int status; +} demux_playlist_t; + +typedef struct { + demux_class_t demux_class; +} demux_playlist_class_t; + + +static playlist_t detect_by_extension (input_plugin_t *input) { + char *ext; + + ext = strrchr (input->get_mrl (input), '.'); + if (!ext) + return XINE_PLT_NONE; + + if (!strcasecmp (ext, ".m3u")) + return XINE_PLT_M3U; + if (!strcasecmp (ext, ".ram")) + return XINE_PLT_RAM; + if (!strcasecmp (ext, ".pls")) + return XINE_PLT_PLS; + if (!strcasecmp (ext, ".wax") || + !strcasecmp (ext, ".wvx") || + !strcasecmp (ext, ".asx")) + return XINE_PLT_ASX; + if (!strcasecmp (ext, ".smi") || + !strcasecmp (ext, ".smil")) + return XINE_PLT_SMI; + if (!strcasecmp (ext, ".qtl")) + return XINE_PLT_QTL; + if (!strcasecmp (ext, ".xspf")) + return XINE_PLT_XSPF; + if (!strcasecmp (ext, ".rss")) + return XINE_PLT_RSS; + + return XINE_PLT_NONE; +} + +static playlist_t detect_by_content (input_plugin_t *input) { + char buf[256], *tmp; + int len; + + len = _x_demux_read_header (input, buf, sizeof(buf)-1); + if (len <= 0) + return XINE_PLT_NONE; + buf[len] = '\0'; + + tmp = buf; + while (*tmp && isspace(*tmp)) + tmp++; + + if (!strncmp (tmp, "[Reference]", 11) || + !strncmp (tmp, "Ref1=", 5)) + return XINE_PLT_REF; + if (!strncmp (tmp, "#EXTM3U", 7)) + return XINE_PLT_M3U; + if (!strncmp (tmp, "file://", 7) || + !strncmp (tmp, "http://", 7) || + !strncmp (tmp, "rtsp://", 7) || + !strncmp (tmp, "pnm://", 6)) + return XINE_PLT_RAM; + if (!strncmp (tmp, "[Playlist]", 10 )) + return XINE_PLT_PLS; + if (!strncasecmp (tmp, "<ASX", 4)) + return XINE_PLT_ASX; + if (!strncmp (tmp, "<smil", 5)) + return XINE_PLT_SMI; + if (!strncmp (tmp, "<?quicktime", 11)) + return XINE_PLT_QTL; + if (!strncmp (tmp, "<playlist", 9)) + return XINE_PLT_XSPF; + if (!strncmp (tmp, "<rss", 4)) + return XINE_PLT_RSS; + + if (!strncmp (tmp, "<?xml", 5)) { + tmp += 5; + while ((tmp = strchr (tmp, '<'))) { + if (!strncasecmp (tmp, "<ASX", 4)) + return XINE_PLT_ASX; + if (!strncmp (tmp, "<smil", 5)) + return XINE_PLT_SMI; + if (!strncmp (tmp, "<?quicktime", 11)) + return XINE_PLT_QTL; + if (!strncmp (tmp, "<playlist", 9)) + return XINE_PLT_XSPF; + if (!strncmp (tmp, "<rss", 4)) + return XINE_PLT_RSS; + tmp++; + } + } + + return XINE_PLT_NONE; +} + +static char* trim (char *s) { + char *e; + + while (*s && isspace(*s)) + s++; + + e = s + strlen(s) - 1; + while (e > s && isspace(*e)) + *e-- = '\0'; + + return s; +} + +static int parse_time (const char *s) { + int t = 0; + int i; + + if (!s) + return 0; + + if (!strncmp (s, "npt=", 4)) + s += 4; + else if (!strncmp (s, "smpte=", 6)) + s += 6; + + for (i = 0; i < 3; i++) { + t *= 60; + t += atoi(s); + s = strchr (s, ':'); + if (!s) + break; + s++; + } + + return t*1000; +} + +static void parse_ref (demux_playlist_t *this, char *data, int length) { + char *src = data; + char *end; + int alt = 0; + + while (src && *src) { + end = strchr (src, '\n'); + if (end) + *end = '\0'; + + src = trim (src); + if (!strncmp (src, "Ref", 3)) { + src = strchr (src, '='); + if (src && *(src+1)) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, alt++, src+1, NULL, 0, 0); + } + } + + src = end; + if (src) + src++; + } +} + +static void parse_m3u (demux_playlist_t *this, char *data, int length) { + char *src = data; + char *end; + char *title = NULL; + + while (src && *src) { + end = strchr (src, '\n'); + if (end) + *end = '\0'; + + src = trim (src); + if (*src == '#') { + if (!strncmp (src+1, "EXTINF:", 7)) { + title = strchr (src+8, ','); + if (title) + title++; + } + } + else if (*src) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, title, 0, 0); + } + + src = end; + if (src) + src++; + } +} + +static void parse_ram (demux_playlist_t *this, char *data, int length) { + char *src = data; + char *end; + + while (src && *src) { + end = strchr (src, '\n'); + if (end) + *end = '\0'; + + src = trim (src); + if (!strcmp (src, "--stop--")) + break; + + if (*src && *src != '#') { + char *title = NULL; + + if (!strncmp (src, "rtsp://", 7) || !strncmp (src, "pnm://", 7)) { + char *tmp = strrchr (src, '?'); + if (tmp) { + *tmp = '\0'; + title = strstr (tmp+1, "title="); + if (title) { + title += 6; + tmp = strchr (title, '&'); + if (tmp) + *tmp = '\0'; + } + } + } + + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, title, 0, 0); + } + + src = end; + if (src) + src++; + } +} + +static void parse_pls (demux_playlist_t *this, char *data, int length) { + char *src = data; + char *end; + + while (src && *src) { + end = strchr (src, '\n'); + if (end) + *end = '\0'; + + src = trim (src); + if (!strncmp (src, "File", 4)) { + src = strchr (src+4, '='); + if (src && *(src+1)) { + lprintf ("mrl:'%s'\n", src+1); + _x_demux_send_mrl_reference (this->stream, 0, src+1, NULL, 0, 0); + } + } + + src = end; + if (src) + src++; + } +} + +static void parse_asx (demux_playlist_t *this, char *data, int length) { + xml_node_t *root, *node, *tmp; + int is_asx = 0; + + xml_parser_init (data, length, XML_PARSER_CASE_INSENSITIVE); + + if (xml_parser_build_tree (&root) >= 0) { + if (!strcasecmp (root->name, "asx")) { + is_asx = 1; + + for (node = root->child; node; node = node->next) { + if (!strcasecmp (node->name, "entry")) { + const char *title = NULL; + const char *src = NULL; + const char *start = NULL; + const char *duration = NULL; + + for (tmp = node->child; tmp; tmp = tmp->next) { + if (!strcasecmp (tmp->name, "title")) { + title = tmp->data; + } + else if (!strcasecmp (tmp->name, "ref")) { + src = xml_parser_get_property (tmp, "href"); + } + else if (!strcasecmp (tmp->name, "starttime")) { + start = xml_parser_get_property (tmp, "value"); + } + else if (!strcasecmp (tmp->name, "duration")) { + duration = xml_parser_get_property (tmp, "value"); + } + } + + if (src) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, title, + parse_time(start), parse_time(duration)); + } + } + } + } + + xml_parser_free_tree (root); + } + + if (!is_asx) { + /* No tags found? Might be a references list. */ + parse_ref (this, data, length); + } +} + +static void parse_smi (demux_playlist_t *this, char *data, int length) { + xml_node_t *root, *node, *tmp; + int is_smi = 0; + + xml_parser_init (data, length, XML_PARSER_CASE_SENSITIVE); + + if (xml_parser_build_tree (&root) >= 0) { + for (node = root; node; node = node->next) { + if (!strcmp (node->name, "smil")) + break; + } + + if (node) { + is_smi = 1; + + for (node = node->child; node; node = node->next) { + if (!strcmp (node->name, "body")) { + for (tmp = node->child; tmp; tmp = tmp->next) { + if (!strcmp (tmp->name, "audio") || !strcmp (tmp->name, "video")) { + const char *src, *title; + int start, end; + + src = xml_parser_get_property (tmp, "src"); + title = xml_parser_get_property (tmp, "title"); + start = parse_time (xml_parser_get_property (tmp, "clipBegin") ? : + xml_parser_get_property (tmp, "clip-begin")); + end = parse_time (xml_parser_get_property (tmp, "clipEnd") ? : + xml_parser_get_property (tmp, "clip-end")); + + if (src) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, title, + start, end ? (end-start) : 0); + } + } + } + } + } + } + + xml_parser_free_tree (root); + } + + if (!is_smi) { + /* No tags found? Might be a RAM playlist. */ + parse_ram (this, data, length); + } +} + +static void parse_qtl (demux_playlist_t *this, char *data, int length) { + xml_node_t *root, *node; + + xml_parser_init (data, length, XML_PARSER_CASE_SENSITIVE); + + if (xml_parser_build_tree (&root) >= 0) { + for (node = root; node; node = node->next) { + if (!strcmp (node->name, "embed")) { + const char *src; + + src = xml_parser_get_property (node, "src"); + if (src) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, NULL, 0, 0); + } + } + } + + xml_parser_free_tree (root); + } +} + +static void parse_xspf (demux_playlist_t *this, char *data, int length) { + xml_node_t *root, *node, *tmp; + + xml_parser_init (data, length, XML_PARSER_CASE_SENSITIVE); + + if (xml_parser_build_tree (&root) >= 0) { + for (node = root; node; node = node->next) { + if (!strcmp (node->name, "playlist")) + break; + } + if (node) { + for (node = node->child; node; node = node->next) { + if (!strcmp (node->name, "trackList")) + break; + } + } + if (node) { + for (node = node->child; node; node = node->next) { + if (!strcmp (node->name, "track")) { + char *src = NULL; + char *title = NULL; + + for (tmp = node->child; tmp; tmp = tmp->next) { + if (!strcmp (tmp->name, "location")) { + src = trim((char*)tmp->data); + } + else if (!strcmp (tmp->name, "title")) { + title = trim((char*)tmp->data); + } + } + + if (src) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, title, 0, 0); + } + } + } + } + + xml_parser_free_tree (root); + } +} + +static void parse_rss (demux_playlist_t *this, char *data, int length) { + xml_node_t *root, *node, *item, *tmp; + + xml_parser_init (data, length, XML_PARSER_CASE_SENSITIVE); + + if (xml_parser_build_tree (&root) >= 0) { + for (node = root; node; node = node->next) { + if (!strcmp (node->name, "rss")) + break; + } + + if (node) { + for (node = node->child; node; node = node->next) { + if (strcmp (node->name, "channel")) + continue; + + for (item = node->child; item; item = item->next) { + if (!strcmp (item->name, "item")) { + const char *title = NULL; + const char *src = NULL; + + for (tmp = item->child; tmp; tmp = tmp->next) { + if (!strcmp (tmp->name, "title")) { + title = tmp->data; + } + else if (!strcmp (tmp->name, "enclosure")) { + src = xml_parser_get_property (tmp, "url"); + } + } + + if (src) { + lprintf ("mrl:'%s'\n", src); + _x_demux_send_mrl_reference (this->stream, 0, src, title, 0, 0); + } + } + } + } + } + + xml_parser_free_tree (root); + } +} + + +static void demux_playlist_send_headers (demux_plugin_t *this_gen) { + demux_playlist_t *this = (demux_playlist_t *) this_gen; + + this->status = DEMUX_OK; + + _x_demux_control_start (this->stream); + + this->input->seek (this->input, 0, SEEK_SET); +} + + +static int demux_playlist_send_chunk (demux_plugin_t *this_gen) { + demux_playlist_t *this = (demux_playlist_t *) this_gen; + char *data = NULL; + int length; + + length = this->input->get_length (this->input); + if (length > 0) { + data = xine_xmalloc (length+1); + if (data) + this->input->read (this->input, data, length); + } + else { + char buf[1024]; + int len; + + length = 0; + while ((len = this->input->read (this->input, buf, sizeof(buf))) > 0) { + data = realloc (data, length+len+1); + if (!data) + break; + + memcpy (data+length, buf, len); + length += len; + data[length] = '\0'; + } + } + + lprintf ("data:%p length:%d\n", data, length); + + if (data) { + switch (this->playlist) { + case XINE_PLT_REF: + parse_ref (this, data, length); + break; + case XINE_PLT_M3U: + parse_m3u (this, data, length); + break; + case XINE_PLT_RAM: + parse_ram (this, data, length); + break; + case XINE_PLT_PLS: + parse_pls (this, data, length); + break; + case XINE_PLT_ASX: + parse_asx (this, data, length); + break; + case XINE_PLT_SMI: + parse_smi (this, data, length); + break; + case XINE_PLT_QTL: + parse_qtl (this, data, length); + break; + case XINE_PLT_XSPF: + parse_xspf (this, data, length); + break; + case XINE_PLT_RSS: + parse_rss (this, data, length); + break; + default: + lprintf ("unexpected playlist type 0x%08x\n", this->playlist); + break; + } + + free (data); + } + + this->status = DEMUX_FINISHED; + + return DEMUX_FINISHED; +} + +static int demux_playlist_seek (demux_plugin_t *this_gen, + off_t start_pos, int start_time, int playing) { + return DEMUX_OK; +} + +static void demux_playlist_dispose (demux_plugin_t *this_gen) { + demux_playlist_t *this = (demux_playlist_t *) this_gen; + + free (this); +} + +static int demux_playlist_get_status (demux_plugin_t *this_gen) { + demux_playlist_t *this = (demux_playlist_t *) this_gen; + + return this->status; +} + +static int demux_playlist_get_stream_length (demux_plugin_t *this_gen) { + return 0; +} + +static uint32_t demux_playlist_get_capabilities (demux_plugin_t *this_gen) { + return DEMUX_CAP_NOCAP; +} + +static int demux_playlist_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) { + demux_playlist_t *this; + + this = xine_xmalloc (sizeof (demux_playlist_t)); + this->xine = stream->xine; + this->stream = stream; + this->input = input; + + this->demux_plugin.send_headers = demux_playlist_send_headers; + this->demux_plugin.send_chunk = demux_playlist_send_chunk; + this->demux_plugin.seek = demux_playlist_seek; + this->demux_plugin.dispose = demux_playlist_dispose; + this->demux_plugin.get_status = demux_playlist_get_status; + this->demux_plugin.get_stream_length = demux_playlist_get_stream_length; + this->demux_plugin.get_capabilities = demux_playlist_get_capabilities; + this->demux_plugin.get_optional_data = demux_playlist_get_optional_data; + this->demux_plugin.demux_class = class_gen; + + switch (stream->content_detection_method) { + case METHOD_BY_EXTENSION: + lprintf ("detect by extension\n"); + this->playlist = detect_by_extension (input); + if (!this->playlist) { + free (this); + return NULL; + } + break; + + case METHOD_BY_CONTENT: + case METHOD_EXPLICIT: + lprintf ("detect by content\n"); + this->playlist = detect_by_content (input); + if (!this->playlist) { + free (this); + return NULL; + } + break; + + default: + free (this); + return NULL; + } + + lprintf ("playlist:0x%08x (%s)\n", this->playlist, (char*)&this->playlist); + + return &this->demux_plugin; +} + +static const char *get_description (demux_class_t *this_gen) { + return "Playlist demux plugin"; +} + +static const char *get_identifier (demux_class_t *this_gen) { + return "playlist"; +} + +static const char *get_extensions (demux_class_t *this_gen) { + return "m3u ram pls asx wax wvx smi smil qtl xspf rss"; +} + +static const char *get_mimetypes (demux_class_t *this_gen) { + return "audio/mpegurl: m3u: M3U playlist;" + "audio/x-mpegurl: m3u: M3U playlist;" + //"audio/x-pn-realaudio: ram: RAM playlist;" + //"audio/vnd.rn-realaudio: ram: RAM playlist;" + "audio/x-scpls: pls: Winamp playlist;" + "audio/x-ms-wax: wax, asx: WAX playlist;" + "audio/x-ms-wvx: wvx, asx: WVX playlist;" + "application/smil: smi, smil: SMIL playlist;" + "application/x-quicktimeplayer: qtl: Quicktime playlist;" + "application/xspf+xml: xspf: XSPF playlist;"; +} + +static void class_dispose (demux_class_t *this_gen) { + demux_playlist_class_t *this = (demux_playlist_class_t *) this_gen; + + free (this); +} + +static void *init_plugin (xine_t *xine, void *data) { + demux_playlist_class_t *this; + + this = xine_xmalloc (sizeof(demux_playlist_class_t)); + + 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 + */ +static const demuxer_info_t demux_info_flv = { + 10 /* priority */ +}; + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_DEMUX, 26, "playlist", XINE_VERSION_CODE, &demux_info_flv, init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index b9fadc804..89d0283ac 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -107,6 +107,8 @@ typedef unsigned int qt_atom; #define UDTA_ATOM QT_ATOM('u', 'd', 't', 'a') #define META_ATOM QT_ATOM('m', 'e', 't', 'a') +#define HDLR_ATOM QT_ATOM('h', 'd', 'l', 'r') +#define ILST_ATOM QT_ATOM('i', 'l', 's', 't') #define NAM_ATOM QT_ATOM(0xA9, 'n', 'a', 'm') #define CPY_ATOM QT_ATOM(0xA9, 'c', 'p', 'y') #define DES_ATOM QT_ATOM(0xA9, 'd', 'e', 's') @@ -133,8 +135,10 @@ typedef unsigned int qt_atom; #define MAX_PTS_DIFF 100000 -/* network bandwidth, cribbed from src/input/input_mms.c */ -const int64_t bandwidths[]={14400,19200,28800,33600,34430,57600, +/** + * @brief Network bandwidth, cribbed from src/input/input_mms.c + */ +static const int64_t bandwidths[]={14400,19200,28800,33600,34430,57600, 115200,262200,393216,524300,1544000,10485800}; /* these are things that can go wrong */ @@ -401,6 +405,10 @@ typedef struct { * demuxer is sending off to the audio decoder */ #define DEBUG_AUDIO_DEMUX 0 +/* define DEBUG_META_LOAD as 1 to see details about the metadata chunks the + * demuxer is reading from the file */ +#define DEBUG_META_LOAD 0 + /* Define DEBUG_DUMP_MOOV as 1 to dump the raw moov atom to disk. This is * particularly useful in debugging a file with a compressed moov (cmov) * atom. The atom will be dumped to the filename specified as @@ -408,10 +416,6 @@ typedef struct { #define DEBUG_DUMP_MOOV 0 #define RAW_MOOV_FILENAME "moovatom.raw" -#ifndef __GNUC__ -#define __attribute__(x) -#endif - #if DEBUG_ATOM_LOAD #define debug_atom_load printf #else @@ -442,6 +446,12 @@ static inline void XINE_FORMAT_PRINTF(1, 2) debug_video_demux(const char *format static inline void XINE_FORMAT_PRINTF(1, 2) debug_audio_demux(const char *format, ...) {} #endif +#if DEBUG_META_LOAD +#define debug_meta_load printf +#else +static inline void XINE_FORMAT_PRINTF(1, 2) debug_meta_load(const char *format, ...) {} +#endif + static inline void dump_moov_atom(unsigned char *moov_atom, int moov_atom_size) { #if DEBUG_DUMP_MOOV @@ -726,52 +736,114 @@ static int is_qt_file(input_plugin_t *qt_file) { } } +static char *parse_data_atom(unsigned char *data_atom) { + const uint32_t data_atom_size = _X_BE_32(&data_atom[0]); + + static const int data_atom_max_version = 0; + const int data_atom_version = data_atom[8]; + + const size_t alloc_size = data_atom_size - 8 + 1; + char *alloc_str = NULL; + + if ( data_atom_version > data_atom_max_version ) { + debug_meta_load("demux_qt: version %d for data atom is higher than the highest supported version (%d)\n", + data_atom_version, data_atom_max_version); + return NULL; + } + + alloc_str = xine_xmalloc(alloc_size); + xine_fast_memcpy(alloc_str, &data_atom[16], alloc_size-1); + alloc_str[alloc_size-1] = '\0'; + + debug_meta_load("demux_qt: got a string of size %zd (%s)\n", alloc_size, alloc_str); + + return alloc_str; +} + /* parse out a meta data atom */ static void parse_meta_atom(qt_info *info, unsigned char *meta_atom) { - int i; - unsigned int meta_atom_size = _X_BE_32(&meta_atom[0]); - qt_atom current_atom; - int string_size; - - for (i = 0; i < meta_atom_size - 4; i++) { - current_atom = _X_BE_32(&meta_atom[i]); - - if (current_atom == ART_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->artist = xine_xmalloc(string_size); - strncpy(info->artist, &meta_atom[i + 20], string_size - 1); - info->artist[string_size - 1] = 0; - } else if (current_atom == NAM_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->name = xine_xmalloc(string_size); - strncpy(info->name, &meta_atom[i + 20], string_size - 1); - info->name[string_size - 1] = 0; - } else if (current_atom == ALB_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->album = xine_xmalloc(string_size); - strncpy(info->album, &meta_atom[i + 20], string_size - 1); - info->album[string_size - 1] = 0; - } else if (current_atom == GEN_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->genre = xine_xmalloc(string_size); - strncpy(info->genre, &meta_atom[i + 20], string_size - 1); - info->genre[string_size - 1] = 0; - } else if (current_atom == TOO_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->comment = xine_xmalloc(string_size); - strncpy(info->comment, &meta_atom[i + 20], string_size - 1); - info->comment[string_size - 1] = 0; - } else if (current_atom == WRT_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->composer = xine_xmalloc(string_size); - strncpy(info->composer, &meta_atom[i + 20], string_size - 1); - info->composer[string_size - 1] = 0; - } else if (current_atom == DAY_ATOM) { - string_size = _X_BE_32(&meta_atom[i + 4]) - 16 + 1; - info->year = xine_xmalloc(string_size); - strncpy(info->year, &meta_atom[i + 20], string_size - 1); - info->year[string_size - 1] = 0; + static const uint32_t meta_atom_preamble_size = 12; + + const uint32_t meta_atom_size = _X_BE_32(&meta_atom[0]); + + static const int meta_atom_max_version = 0; + const int meta_atom_version = meta_atom[8]; + /* const uint32_t flags = _X_BE_24(&meta_atom[9]); */ + + uint32_t i = meta_atom_preamble_size; + + if ( meta_atom_version > meta_atom_max_version ) { + debug_meta_load("demux_qt: version %d for meta atom is higher than the highest supported version (%d)\n", + meta_atom_version, meta_atom_max_version); + return; + } + + while ( i < meta_atom_size ) { + const uint8_t *const current_atom = &meta_atom[i]; + const qt_atom current_atom_code = _X_BE_32(¤t_atom[4]); + const uint32_t current_atom_size = _X_BE_32(¤t_atom[0]); + uint32_t handler_type = 0; + + switch (current_atom_code) { + case HDLR_ATOM: { + static const int hdlr_atom_max_version = 0; + const int hdlr_atom_version = current_atom[8]; + + /* const uint32_t hdlr_atom_flags = _X_BE_24(¤t_atom[9]); */ + + if ( hdlr_atom_version > hdlr_atom_max_version ) { + debug_meta_load("demux_qt: version %d for hdlr atom is higher than the highest supported version (%d)\n", + hdlr_atom_version, hdlr_atom_max_version); + return; + } + + handler_type = _X_BE_32(¤t_atom[12]); } + break; + + case ILST_ATOM: { + uint32_t j = i + 8; + while ( j < current_atom_size ) { + const uint8_t *const sub_atom = &meta_atom[j]; + const qt_atom sub_atom_code = _X_BE_32(&sub_atom[4]); + const uint32_t sub_atom_size = _X_BE_32(&sub_atom[0]); + + switch(sub_atom_code) { + case ART_ATOM: + info->artist = parse_data_atom(&sub_atom[8]); + break; + case NAM_ATOM: + info->name = parse_data_atom(&sub_atom[8]); + break; + case ALB_ATOM: + info->album = parse_data_atom(&sub_atom[8]); + break; + case GEN_ATOM: + info->genre = parse_data_atom(&sub_atom[8]); + break; + case CMT_ATOM: + info->comment = parse_data_atom(&sub_atom[8]); + break; + case WRT_ATOM: + info->composer = parse_data_atom(&sub_atom[8]); + break; + case DAY_ATOM: + info->year = parse_data_atom(&sub_atom[8]); + break; + default: + debug_meta_load("unknown atom %08x in ilst\n", sub_atom_code); + } + + j += sub_atom_size; + } + } + break; + + default: + debug_meta_load("unknown atom %08x in meta\n", current_atom_code); + } + + i += current_atom_size; } } @@ -813,25 +885,11 @@ static qt_error parse_trak_atom (qt_trak *trak, unsigned char *trak_atom) { int i, j, k; - unsigned int trak_atom_size = _X_BE_32(&trak_atom[0]); - qt_atom current_atom; - unsigned int current_atom_size; + const unsigned int trak_atom_size = _X_BE_32(&trak_atom[0]); unsigned int atom_pos; unsigned int properties_offset; - unsigned int current_stsd_atom_size; qt_error last_error = QT_OK; - /* for palette traversal */ - int color_depth; - int color_flag; - int color_start; - int color_count; - int color_end; - int color_index; - int color_dec; - int color_greyscale; - const unsigned char *color_table; - /* initialize trak structure */ trak->edit_list_count = 0; trak->edit_list_table = NULL; @@ -862,12 +920,13 @@ static qt_error parse_trak_atom (qt_trak *trak, /* search for media type atoms */ for (i = ATOM_PREAMBLE_SIZE; i < trak_atom_size - 4; i++) { - current_atom = _X_BE_32(&trak_atom[i]); + const qt_atom current_atom = _X_BE_32(&trak_atom[i]); - if (current_atom == VMHD_ATOM) { + switch (current_atom) { + case VMHD_ATOM: trak->type = MEDIA_VIDEO; break; - } else if (current_atom == SMHD_ATOM) { + case SMHD_ATOM: trak->type = MEDIA_AUDIO; break; } @@ -879,13 +938,15 @@ static qt_error parse_trak_atom (qt_trak *trak, /* search for the useful atoms */ for (i = ATOM_PREAMBLE_SIZE; i < trak_atom_size - 4; i++) { - current_atom_size = _X_BE_32(&trak_atom[i - 4]); - current_atom = _X_BE_32(&trak_atom[i]); + const current_atom_size = _X_BE_32(&trak_atom[i - 4]); + const current_atom = _X_BE_32(&trak_atom[i]); - if (current_atom == TKHD_ATOM) { + switch(current_atom) { + case TKHD_ATOM: trak->flags = _X_BE_16(&trak_atom[i + 6]); - } else if (current_atom == ELST_ATOM) { + break; + case ELST_ATOM: /* there should only be one edit list table */ if (trak->edit_list_table) { last_error = QT_HEADER_TROUBLE; @@ -915,17 +976,19 @@ static qt_error parse_trak_atom (qt_trak *trak, trak->edit_list_table[j].track_duration, trak->edit_list_table[j].media_time); } + break; - } else if (current_atom == MDHD_ATOM) { - int version; + case MDHD_ATOM: debug_atom_load ("demux_qt: mdhd atom\n"); - - version = trak_atom[i+4]; - if ( version > 1 ) continue; /* unsupported, undocumented */ + { + const int version = trak_atom[i+4]; + if ( version > 1 ) continue; /* unsupported, undocumented */ - trak->timescale = _X_BE_32(&trak_atom[i + (version == 0 ? 0x10 : 0x18) ]); - } else if (current_atom == STSD_ATOM) { + trak->timescale = _X_BE_32(&trak_atom[i + (version == 0 ? 0x10 : 0x18) ]); + } + break; + case STSD_ATOM: debug_atom_load ("demux_qt: stsd atom\n"); #if DEBUG_ATOM_LOAD xine_hexdump (&trak_atom[i], current_atom_size); @@ -933,18 +996,28 @@ static qt_error parse_trak_atom (qt_trak *trak, /* allocate space for each of the properties unions */ trak->stsd_atoms_count = _X_BE_32(&trak_atom[i + 8]); - trak->stsd_atoms = xine_xmalloc(trak->stsd_atoms_count * sizeof(properties_t)); + trak->stsd_atoms = xine_xcalloc(trak->stsd_atoms_count, sizeof(properties_t)); if (!trak->stsd_atoms) { last_error = QT_NO_MEMORY; goto free_trak; } - memset(trak->stsd_atoms, 0, trak->stsd_atoms_count * sizeof(properties_t)); atom_pos = i + 0x10; properties_offset = 0x0C; for (k = 0; k < trak->stsd_atoms_count; k++) { - current_stsd_atom_size = _X_BE_32(&trak_atom[atom_pos - 4]); + const uint32_t current_stsd_atom_size = _X_BE_32(&trak_atom[atom_pos - 4]); + + /* for palette traversal */ + int color_depth; + int color_flag; + int color_start; + int color_count; + int color_end; + int color_index; + int color_dec; + int color_greyscale; + const unsigned char *color_table; if (trak->type == MEDIA_VIDEO) { @@ -1225,7 +1298,7 @@ static qt_error parse_trak_atom (qt_trak *trak, (_X_BE_32(&trak_atom[atom_pos + 0x34]) == WAVE_ATOM) && (_X_BE_32(&trak_atom[atom_pos + 0x3C]) == FRMA_ATOM) && (_X_ME_32(&trak_atom[atom_pos + 0x48]) == trak->stsd_atoms[k].audio.codec_fourcc)) { - int wave_size = _X_BE_32(&trak_atom[atom_pos + 0x44]) - 8; + const int wave_size = _X_BE_32(&trak_atom[atom_pos + 0x44]) - 8; if ((wave_size >= sizeof(xine_waveformatex)) && (current_atom_size >= (0x4C + wave_size))) { @@ -1275,15 +1348,15 @@ static qt_error parse_trak_atom (qt_trak *trak, atom_pos += current_stsd_atom_size; properties_offset += current_stsd_atom_size; } - - } else if (current_atom == ESDS_ATOM) { - - uint32_t len; + break; + + case ESDS_ATOM: debug_atom_load(" qt/mpeg-4 esds atom\n"); if ((trak->type == MEDIA_VIDEO) || (trak->type == MEDIA_AUDIO)) { + uint32_t len; j = i + 8; if( trak_atom[j++] == 0x03 ) { @@ -1306,17 +1379,17 @@ static qt_error parse_trak_atom (qt_trak *trak, } } } + break; - } else if (current_atom == AVCC_ATOM) { - + case AVCC_ATOM: debug_atom_load(" avcC atom\n"); trak->decoder_config_len = current_atom_size - 8; trak->decoder_config = realloc(trak->decoder_config, trak->decoder_config_len); memcpy(trak->decoder_config, &trak_atom[i + 4], trak->decoder_config_len); + break; - } else if (current_atom == STSZ_ATOM) { - + case STSZ_ATOM: /* there should only be one of these atoms */ if (trak->sample_size_table) { last_error = QT_HEADER_TROUBLE; @@ -1348,9 +1421,9 @@ static qt_error parse_trak_atom (qt_trak *trak, /* set the pointer to non-NULL to indicate that the atom type has * already been seen for this trak atom */ trak->sample_size_table = (void *)-1; + break; - } else if (current_atom == STSS_ATOM) { - + case STSS_ATOM: /* there should only be one of these atoms */ if (trak->sync_sample_table) { last_error = QT_HEADER_TROUBLE; @@ -1377,9 +1450,9 @@ static qt_error parse_trak_atom (qt_trak *trak, j, trak->sync_sample_table[j], trak->sync_sample_table[j] - 1); } + break; - } else if (current_atom == STCO_ATOM) { - + case STCO_ATOM: /* there should only be one of either stco or co64 */ if (trak->chunk_offset_table) { last_error = QT_HEADER_TROUBLE; @@ -1405,9 +1478,9 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" chunk %d @ 0x%"PRIX64"\n", j, trak->chunk_offset_table[j]); } + break; - } else if (current_atom == CO64_ATOM) { - + case CO64_ATOM: /* there should only be one of either stco or co64 */ if (trak->chunk_offset_table) { last_error = QT_HEADER_TROUBLE; @@ -1436,9 +1509,9 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" chunk %d @ 0x%"PRIX64"\n", j, trak->chunk_offset_table[j]); } + break; - } else if (current_atom == STSC_ATOM) { - + case STSC_ATOM: /* there should only be one of these atoms */ if (trak->sample_to_chunk_table) { last_error = QT_HEADER_TROUBLE; @@ -1471,9 +1544,9 @@ static qt_error parse_trak_atom (qt_trak *trak, trak->sample_to_chunk_table[j].first_chunk - 1, trak->sample_to_chunk_table[j].media_id); } + break; - } else if (current_atom == STTS_ATOM) { - + case STTS_ATOM: /* there should only be one of these atoms */ if (trak->time_to_sample_table) { last_error = QT_HEADER_TROUBLE; @@ -1533,9 +1606,7 @@ static qt_error parse_reference_atom (reference_t *ref, char *base_mrl) { int i, j; - unsigned int ref_atom_size = _X_BE_32(&ref_atom[0]); - qt_atom current_atom; - unsigned int current_atom_size; + const unsigned int ref_atom_size = _X_BE_32(&ref_atom[0]); /* initialize reference atom */ ref->url = NULL; @@ -1544,11 +1615,11 @@ static qt_error parse_reference_atom (reference_t *ref, /* traverse through the atom looking for the key atoms */ for (i = ATOM_PREAMBLE_SIZE; i < ref_atom_size - 4; i++) { + const uint32_t current_atom_size = _X_BE_32(&ref_atom[i - 4]); + const qt_atom current_atom = _X_BE_32(&ref_atom[i]); - current_atom_size = _X_BE_32(&ref_atom[i - 4]); - current_atom = _X_BE_32(&ref_atom[i]); - - if (current_atom == RDRF_ATOM) { + switch (current_atom) { + case RDRF_ATOM: /* if the URL starts with "http://", copy it */ if (strncmp(&ref_atom[i + 16], "http://", 7) == 0 @@ -1577,17 +1648,17 @@ static qt_error parse_reference_atom (reference_t *ref, } debug_atom_load(" qt rdrf URL reference:\n %s\n", ref->url); + break; - } else if (current_atom == RMDR_ATOM) { - + case RMDR_ATOM: /* load the data rate */ ref->data_rate = _X_BE_32(&ref_atom[i + 8]); ref->data_rate *= 10; debug_atom_load(" qt rmdr data rate = %"PRId64"\n", ref->data_rate); + break; - } else if (current_atom == RMVC_ATOM) { - + case RMVC_ATOM: debug_atom_load(" qt rmvc atom\n"); /* search the rmvc atom for 'qtim'; 2 bytes will follow the qtim @@ -1915,7 +1986,6 @@ static void parse_moov_atom(qt_info *info, unsigned char *moov_atom, int64_t bandwidth) { int i, j; unsigned int moov_atom_size = _X_BE_32(&moov_atom[0]); - qt_atom current_atom; int string_size, error; unsigned int max_video_frames = 0; unsigned int max_audio_frames = 0; @@ -1930,15 +2000,17 @@ static void parse_moov_atom(qt_info *info, unsigned char *moov_atom, /* prowl through the moov atom looking for very specific targets */ for (i = ATOM_PREAMBLE_SIZE + 4; i < moov_atom_size - 4; i += _X_BE_32(&moov_atom[i - 4])) { - current_atom = _X_BE_32(&moov_atom[i]); + const qt_atom current_atom = _X_BE_32(&moov_atom[i]); - if (current_atom == MVHD_ATOM) { + switch (current_atom) { + case MVHD_ATOM: parse_mvhd_atom(info, &moov_atom[i - 4]); if (info->last_error != QT_OK) return; - } else if (current_atom == TRAK_ATOM) { + break; + case TRAK_ATOM: /* create a new trak structure */ info->trak_count++; info->traks = (qt_trak *)realloc(info->traks, @@ -1950,44 +2022,50 @@ static void parse_moov_atom(qt_info *info, unsigned char *moov_atom, info->trak_count--; return; } + break; + + case UDTA_ATOM: + parse_meta_atom(info, &moov_atom[i + 4]); + if (info->last_error != QT_OK) + return; + break; - } else if (current_atom == META_ATOM) { - + case META_ATOM: parse_meta_atom(info, &moov_atom[i - 4]); if (info->last_error != QT_OK) return; + break; - } else if (current_atom == NAM_ATOM) { - + case NAM_ATOM: string_size = _X_BE_16(&moov_atom[i + 4]) + 1; info->name = realloc (info->name, string_size); strncpy(info->name, &moov_atom[i + 8], string_size - 1); info->name[string_size - 1] = 0; + break; - } else if (current_atom == CPY_ATOM) { - + case CPY_ATOM: string_size = _X_BE_16(&moov_atom[i + 4]) + 1; info->copyright = realloc (info->copyright, string_size); strncpy(info->copyright, &moov_atom[i + 8], string_size - 1); info->copyright[string_size - 1] = 0; + break; - } else if (current_atom == DES_ATOM) { - + case DES_ATOM: string_size = _X_BE_16(&moov_atom[i + 4]) + 1; info->description = realloc (info->description, string_size); strncpy(info->description, &moov_atom[i + 8], string_size - 1); info->description[string_size - 1] = 0; + break; - } else if (current_atom == CMT_ATOM) { - + case CMT_ATOM: string_size = _X_BE_16(&moov_atom[i + 4]) + 1; info->comment = realloc (info->comment, string_size); strncpy(info->comment, &moov_atom[i + 8], string_size - 1); info->comment[string_size - 1] = 0; + break; - } else if (current_atom == RMDA_ATOM || - current_atom == RMRA_ATOM) { - + case RMDA_ATOM: + case RMRA_ATOM: /* create a new reference structure */ info->reference_count++; info->references = (reference_t *)realloc(info->references, @@ -1995,8 +2073,9 @@ static void parse_moov_atom(qt_info *info, unsigned char *moov_atom, parse_reference_atom(&info->references[info->reference_count - 1], &moov_atom[i - 4], info->base_mrl); + break; - } else { + default: debug_atom_load(" qt: unknown atom into the moov atom (0x%08X)\n", current_atom); } } diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 11c5069eb..60fa91451 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -690,7 +690,7 @@ unknown: this->video_stream->mdpr->avg_bit_rate); /* Allocate fragment offset table */ - this->fragment_tab = xine_xmalloc(FRAGMENT_TAB_SIZE*sizeof(uint32_t)); + this->fragment_tab = xine_xcalloc(FRAGMENT_TAB_SIZE, sizeof(uint32_t)); this->fragment_tab_max = FRAGMENT_TAB_SIZE; } @@ -1280,7 +1280,7 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { frames = (stream_read_word(this) & 0xf0) >> 4; /* 2 bytes per frame size */ - sizes = xine_xmalloc(frames*sizeof(int)); + sizes = xine_xcalloc(frames, sizeof(int)); for(i = 0; i < frames; i++) sizes[i] = stream_read_word(this); diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c index 70c9b310a..1e7c3c7de 100644 --- a/src/demuxers/demux_realaudio.c +++ b/src/demuxers/demux_realaudio.c @@ -311,8 +311,6 @@ static int demux_ra_get_status (demux_plugin_t *this_gen) { /* return the approximate length in miliseconds */ static int demux_ra_get_stream_length (demux_plugin_t *this_gen) { - demux_ra_t *this = (demux_ra_t *) this_gen; - return 0; } diff --git a/src/demuxers/demux_ts.c b/src/demuxers/demux_ts.c index 3ed6bcecd..52d6c7690 100644 --- a/src/demuxers/demux_ts.c +++ b/src/demuxers/demux_ts.c @@ -1331,7 +1331,6 @@ printf("Program Number is %i, looking for %i\n",program_number,this->program_num case ISO_13818_PES_PRIVATE: for (i = 5; i < coded_length; i += stream[i+1] + 2) { if ((stream[i] == 0x6a) && (this->audio_tracks_count < MAX_AUDIO_TRACKS)) { - uint32_t format_identifier=0; int i, found = 0; for(i = 0; i < this->audio_tracks_count; i++) { if(this->audio_tracks[i].pid == pid) { @@ -2271,9 +2270,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, this->status = DEMUX_FINISHED; #ifdef TS_READ_STATS - for (i=0; i<=NPKT_PER_READ; i++) { - this->rstat[i] = 0; - } + memset(this-rstat, 0, sizeof(*this->rstat)*NPKT_PER_READ); #endif /* DVBSUB */ diff --git a/src/demuxers/demux_tta.c b/src/demuxers/demux_tta.c index f6eadd652..9b2730018 100644 --- a/src/demuxers/demux_tta.c +++ b/src/demuxers/demux_tta.c @@ -30,6 +30,7 @@ #include "buffer.h" #include "bswap.h" #include "group_audio.h" +#include "attributes.h" typedef struct { demux_plugin_t demux_plugin; @@ -54,7 +55,7 @@ typedef struct { uint32_t samplerate; uint32_t data_length; uint32_t crc32; - } __attribute__((__packed__)) tta; + } XINE_PACKED tta; uint8_t buffer[22]; /* This is the size of the header */ } header; } demux_tta_t; @@ -63,16 +64,14 @@ typedef struct { demux_class_t demux_class; } demux_tta_class_t; -#define FOURCC_32(a, b, c, d) (d + (c<<8) + (b<<16) + (a<<24)) - static int open_tta_file(demux_tta_t *this) { - uint8_t peek[4]; + uint32_t peek; uint32_t framelen; - if (_x_demux_read_header(this->input, peek, 4) != 4) + if (_x_demux_read_header(this->input, &peek, 4) != 4) return 0; - if ( _X_BE_32(peek) != FOURCC_32('T', 'T', 'A', '1') ) + if ( peek != ME_FOURCC('T', 'T', 'A', '1') ) return 0; if ( this->input->read(this->input, this->header.buffer, sizeof(this->header)) != sizeof(this->header) ) @@ -87,7 +86,7 @@ static int open_tta_file(demux_tta_t *this) { return 0; } - this->seektable = xine_xmalloc(sizeof(uint32_t)*this->totalframes); + this->seektable = xine_xcalloc(this->totalframes, sizeof(uint32_t)); this->input->read(this->input, this->seektable, sizeof(uint32_t)*this->totalframes); /* Skip the CRC32 */ diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c index 596d47f4a..a69c6b46a 100644 --- a/src/demuxers/demux_wc3movie.c +++ b/src/demuxers/demux_wc3movie.c @@ -378,17 +378,15 @@ static int open_mve_file(demux_mve_t *this) { this->number_of_shots = _X_LE_32(&preamble[0]); /* allocate space for the shot offset index and set offsets to 0 */ - this->shot_offsets = xine_xmalloc(this->number_of_shots * sizeof(off_t)); + this->shot_offsets = xine_xcalloc(this->number_of_shots, sizeof(off_t)); this->current_shot = 0; - for (i = 0; i < this->number_of_shots; i++) - this->shot_offsets[i] = 0; /* skip the SOND chunk */ this->input->seek(this->input, 12, SEEK_CUR); /* load the palette chunks */ - this->palettes = xine_xmalloc(this->number_of_shots * PALETTE_SIZE * - sizeof(palette_entry_t)); + this->palettes = xine_xcalloc(this->number_of_shots, PALETTE_SIZE * + sizeof(palette_entry_t)); for (i = 0; i < this->number_of_shots; i++) { /* make sure there was a valid palette chunk preamble */ if (this->input->read(this->input, preamble, PREAMBLE_SIZE) != diff --git a/src/demuxers/group_audio.c b/src/demuxers/group_audio.c index bd3932b36..8d6c18190 100644 --- a/src/demuxers/group_audio.c +++ b/src/demuxers/group_audio.c @@ -69,10 +69,6 @@ static const demuxer_info_t demux_info_mpc = { 1 /* priority */ }; -static const demuxer_info_t demux_info_nsf = { - 10 /* priority */ -}; - static const demuxer_info_t demux_info_realaudio = { 10 /* priority */ }; @@ -101,12 +97,6 @@ static const demuxer_info_t demux_info_wav = { 6 /* priority */ }; -#ifdef HAVE_MODPLUG -static const demuxer_info_t demux_info_mod = { - 10 /* priority */ -}; -#endif - const plugin_info_t xine_plugin_info[] EXPORTED = { /* type, API, "name", version, special_info, init_function */ { PLUGIN_DEMUX, 26, "aac", XINE_VERSION_CODE, &demux_info_aac, demux_aac_init_plugin }, @@ -118,7 +108,6 @@ const plugin_info_t xine_plugin_info[] EXPORTED = { { PLUGIN_DEMUX, 26, "flac", XINE_VERSION_CODE, &demux_info_flac, demux_flac_init_plugin }, { PLUGIN_DEMUX, 26, "mp3", XINE_VERSION_CODE, &demux_info_mpgaudio, demux_mpgaudio_init_class }, { PLUGIN_DEMUX, 26, "mpc", XINE_VERSION_CODE, &demux_info_mpc, demux_mpc_init_plugin }, - { PLUGIN_DEMUX, 26, "nsf", XINE_VERSION_CODE, &demux_info_nsf, demux_nsf_init_plugin }, { PLUGIN_DEMUX, 26, "realaudio", XINE_VERSION_CODE, &demux_info_realaudio, demux_realaudio_init_plugin }, { PLUGIN_DEMUX, 26, "shn", XINE_VERSION_CODE, &demux_info_shn, demux_shn_init_plugin }, { PLUGIN_DEMUX, 26, "snd", XINE_VERSION_CODE, &demux_info_snd, demux_snd_init_plugin }, @@ -126,8 +115,5 @@ const plugin_info_t xine_plugin_info[] EXPORTED = { { PLUGIN_DEMUX, 26, "voc", XINE_VERSION_CODE, &demux_info_voc, demux_voc_init_plugin }, { PLUGIN_DEMUX, 26, "vox", XINE_VERSION_CODE, &demux_info_vox, demux_vox_init_plugin }, { PLUGIN_DEMUX, 26, "wav", XINE_VERSION_CODE, &demux_info_wav, demux_wav_init_plugin }, -#ifdef HAVE_MODPLUG - { PLUGIN_DEMUX, 26, "mod", XINE_VERSION_CODE, &demux_info_mod, demux_mod_init_plugin }, -#endif { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; diff --git a/src/demuxers/group_audio.h b/src/demuxers/group_audio.h index 6b74d9feb..11aac35d7 100644 --- a/src/demuxers/group_audio.h +++ b/src/demuxers/group_audio.h @@ -32,7 +32,6 @@ void *demux_dts_init_plugin (xine_t *xine, void *data); void *demux_flac_init_plugin (xine_t *xine, void *data); void *demux_mpgaudio_init_class (xine_t *xine, void *data); void *demux_mpc_init_plugin (xine_t *xine, void *data); -void *demux_nsf_init_plugin (xine_t *xine, void *data); void *demux_realaudio_init_plugin (xine_t *xine, void *data); void *demux_shn_init_plugin (xine_t *xine, void *data); void *demux_snd_init_plugin (xine_t *xine, void *data); @@ -41,8 +40,4 @@ void *demux_voc_init_plugin (xine_t *xine, void *data); void *demux_vox_init_plugin (xine_t *xine, void *data); void *demux_wav_init_plugin (xine_t *xine, void *data); -#ifdef HAVE_MODPLUG -void *demux_mod_init_plugin (xine_t *xine, void *data); -#endif - #endif diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index 1613e3a19..8eb413f83 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -335,7 +335,7 @@ static int id3v22_interp_frame(input_plugin_t *input, int id3v22_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header) { + uint8_t *mp3_frame_header) { id3v2_header_t tag_header; id3v22_frame_header_t tag_frame_header; int pos = 0; @@ -528,7 +528,7 @@ static int id3v23_interp_frame(input_plugin_t *input, int id3v23_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header) { + uint8_t *mp3_frame_header) { id3v2_header_t tag_header; id3v23_frame_header_t tag_frame_header; id3v23_frame_ext_header_t tag_frame_ext_header; @@ -779,7 +779,7 @@ static int id3v24_interp_frame(input_plugin_t *input, int id3v24_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header) { + uint8_t *mp3_frame_header) { id3v2_header_t tag_header; id3v24_frame_header_t tag_frame_header; id3v24_frame_ext_header_t tag_frame_ext_header; @@ -847,7 +847,7 @@ int id3v24_parse_tag(input_plugin_t *input, int id3v2_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header) { + uint8_t *mp3_frame_header) { _x_assert(mp3_frame_header[0] == 'I' && mp3_frame_header[1] == 'D' && mp3_frame_header[2] == '3'); int result = 0; diff --git a/src/demuxers/id3.h b/src/demuxers/id3.h index b4ea4b6be..35f011f30 100644 --- a/src/demuxers/id3.h +++ b/src/demuxers/id3.h @@ -153,20 +153,20 @@ int id3v1_parse_tag (input_plugin_t *input, xine_stream_t *stream); int id3v22_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header); + uint8_t *mp3_frame_header); int id3v23_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header); + uint8_t *mp3_frame_header); int id3v24_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header); + uint8_t *mp3_frame_header); /* Generic function that switch between the three above */ int id3v2_parse_tag(input_plugin_t *input, xine_stream_t *stream, - int8_t *mp3_frame_header); + uint8_t *mp3_frame_header); /** * @brief Checks if the given buffer is an ID3 tag preamble |