From 9bf7c5d2554e1f6fc8a525b609a90ffce17caec8 Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Fri, 22 Feb 2008 14:26:49 +0200 Subject: added patch for 16bit big endian DTS detection --HG-- extra : transplant_source : %5C%D4ln%1C%B8Up%88%96R%09%1A%05HQ%3C%F8%CE%08 --- src/demuxers/demux_dts.c | 51 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_dts.c b/src/demuxers/demux_dts.c index 7c9b47fcd..2ea119858 100644 --- a/src/demuxers/demux_dts.c +++ b/src/demuxers/demux_dts.c @@ -140,11 +140,29 @@ static int open_dts_file(demux_dts_t *this) { } } + /* DTS bitstream encoding version + * -1 - not detected + * 0 - 16 bits and big endian + * 1 - 16 bits and low endian (detection not implemented) + * 2 - 14 bits and big endian (detection not implemented) + * 3 - 14 bits and low endian + */ + int dts_version = -1; + /* Look for a valid DTS syncword */ for (i=offset; idata_start = i-4; lprintf("found DTS syncword at offset %d\n", i-4); break; @@ -155,14 +173,24 @@ static int open_dts_file(demux_dts_t *this) { if (i < peak_size-9) { unsigned int nblks, fsize, sfreq; + /* 16 bits and big endian bitstream */ + if (dts_version == 0) { + nblks = ((peak[this->data_start+4] & 0x01) << 6) | + ((peak[this->data_start+5] & 0xfc) >> 2); + fsize = (((peak[this->data_start+5] & 0x03) << 12) |(peak[this->data_start+6] << 4) | + ((peak[this->data_start+7] & 0xf0) >> 4)) + 1; + sfreq = (peak[this->data_start+8] & 0x3c) >> 2; + } /* 14 bits and little endian bitstream */ - nblks = ((peak[this->data_start+4] & 0x07) << 4) | - ((peak[this->data_start+7] & 0x3c) >> 2); - fsize = (((peak[this->data_start+7] & 0x03) << 12) | - (peak[this->data_start+6] << 4) | - ((peak[this->data_start+9] & 0x3c) >> 2)) + 1; - sfreq = peak[this->data_start+8] & 0x0f; + if (dts_version == 3) { + nblks = ((peak[this->data_start+4] & 0x07) << 4) | + ((peak[this->data_start+7] & 0x3c) >> 2); + fsize = (((peak[this->data_start+7] & 0x03) << 12) | + (peak[this->data_start+6] << 4) | + ((peak[this->data_start+9] & 0x3c) >> 2)) + 1; + sfreq = peak[this->data_start+8] & 0x0f; + } if ((sfreq > sizeof(dts_sample_rates)/sizeof(int)) || (dts_sample_rates[sfreq] == 0)) @@ -170,7 +198,16 @@ static int open_dts_file(demux_dts_t *this) { /* Big assumption - this is CBR data */ this->samples_per_frame = (nblks + 1) * 32; - this->frame_size = fsize * 8 / 14 * 2; + + /* 16 bits and big endian bitstream */ + if (dts_version == 0) { + this->frame_size = fsize * 8 / 16 * 2; + } + /* 14 bits and little endian bitstream */ + else if (dts_version == 3) { + this->frame_size = fsize * 8 / 14 * 2; + } + this->sample_rate = dts_sample_rates[sfreq]; lprintf("samples per frame: %d\n", this->samples_per_frame); -- cgit v1.2.3 From f574d29a8c23c07e04c7cdc91e9e9a877ee70277 Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Fri, 29 Feb 2008 13:06:06 +0200 Subject: Added check if DTS data with IEC958 header will fit into frames samples size and send it without IEC958 header otherwise - so the receivers can autodetect the raw DTS stream. --HG-- extra : transplant_source : %7C%02Vm-%DF%B4%CD%8B%B9U3%A7%B9%EDT%3CZ%91%81 --- src/libdts/xine_dts_decoder.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/libdts/xine_dts_decoder.c b/src/libdts/xine_dts_decoder.c index 6573d5ed0..2b5bedb83 100644 --- a/src/libdts/xine_dts_decoder.c +++ b/src/libdts/xine_dts_decoder.c @@ -207,19 +207,27 @@ static void dts_decode_frame (dts_decoder_t *this, int64_t pts, int preview_mode audio_buffer->num_frames = this->ac5_pcm_length; - data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */ - data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */ - data_out[4] = ac5_spdif_type; /* DTS data */ - data_out[5] = 0; /* Unknown */ - data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */ - data_out[7] = ((this->ac5_length ) >> 5) & 0xff; - - if( this->ac5_pcm_length ) { - if( this->ac5_pcm_length % 2) { - swab(data_in, &data_out[8], this->ac5_length ); - } else { - swab(data_in, &data_out[8], this->ac5_length + 1); + // Checking if AC5 data plus IEC958 header will fit into frames samples data + if ( this->ac5_length + 8 <= this->ac5_pcm_length * 2 * 2 ) { + data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */ + data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */ + data_out[4] = ac5_spdif_type; /* DTS data */ + data_out[5] = 0; /* Unknown */ + data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */ + data_out[7] = ((this->ac5_length ) >> 5) & 0xff; + + if( this->ac5_pcm_length ) { + if( this->ac5_pcm_length % 2) { + swab(data_in, &data_out[8], this->ac5_length ); + } else { + swab(data_in, &data_out[8], this->ac5_length + 1); + } } + // Transmit it without header otherwise, receivers will autodetect DTS + } else { + lprintf("AC5 data is too large (%i > %i), sending without IEC958 header\n", + this->ac5_length + 8, this->ac5_pcm_length * 2 * 2); + memcpy(data_out, data_in, this->ac5_length); } } else { /* Software decode */ -- cgit v1.2.3 From 4c70acb313cc8b0a5cc769e736ee30726af90cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sat, 1 Mar 2008 16:42:09 +0100 Subject: Support the new FFmpeg include layout. Now the same include directive should work for both internal and external FFmpeg (with new layout). --- src/post/planar/pp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/post/planar/pp.c b/src/post/planar/pp.c index e13119311..bc7cc1928 100644 --- a/src/post/planar/pp.c +++ b/src/post/planar/pp.c @@ -23,9 +23,14 @@ #include "xine_internal.h" #include "post.h" #include "xineutils.h" -#include "postprocess.h" #include +#ifdef HAVE_FFMPEG_AVCODEC_H +# include +#else +# include +#endif + #define PP_STRING_SIZE 256 /* size of pp mode string (including all options) */ /* plugin class initialization function */ -- cgit v1.2.3 From 6772044da2f3574f09b8f39832710daab249e83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sun, 2 Mar 2008 18:52:09 +0100 Subject: Backport the MANGLE macro handling from 1.2-libavutil branch (and adapt). --- src/libw32dll/wine/Makefile.am | 3 +- src/libw32dll/wine/win32.c | 8 ++-- src/post/deinterlace/plugins/Makefile.am | 2 +- .../plugins/tomsmocomp/tomsmocompmacros.h | 2 + src/xine-utils/Makefile.am | 2 +- src/xine-utils/mangle.h | 50 ++++++++++++++++++++++ 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 src/xine-utils/mangle.h (limited to 'src') diff --git a/src/libw32dll/wine/Makefile.am b/src/libw32dll/wine/Makefile.am index 63da4068e..70341a502 100644 --- a/src/libw32dll/wine/Makefile.am +++ b/src/libw32dll/wine/Makefile.am @@ -9,7 +9,8 @@ noinst_LTLIBRARIES = $(wine_lib) AM_CFLAGS = $(X_CFLAGS) @W32_NO_OPTIMIZE@ \ -Wmissing-prototypes -Wimplicit-function-declaration \ -DWIN32_PATH=\"@w32_path@\" -I$(srcdir)/.. -D__WINE__ \ - -Ddbg_printf=__vprintf -DTRACE=__vprintf + -Ddbg_printf=__vprintf -DTRACE=__vprintf \ + -I$(top_srcdir)/src/xine-utils # CFLAGS is here to filter out -fomit-frame-pointer, # -finline-functions and -frename-registers because they cause bad diff --git a/src/libw32dll/wine/win32.c b/src/libw32dll/wine/win32.c index 3b0941391..9b627a10a 100644 --- a/src/libw32dll/wine/win32.c +++ b/src/libw32dll/wine/win32.c @@ -5058,11 +5058,9 @@ struct libs libraries[]={ LL(ddraw) #endif }; -#if defined(__CYGWIN__) || defined(__OS2__) || defined (__OpenBSD__) -#define MANGLE(a) "_" #a -#else -#define MANGLE(a) #a -#endif + +#include "mangle.h" + static void ext_stubs(void) { // expects: diff --git a/src/post/deinterlace/plugins/Makefile.am b/src/post/deinterlace/plugins/Makefile.am index 1ff139d29..5f0997eb8 100644 --- a/src/post/deinterlace/plugins/Makefile.am +++ b/src/post/deinterlace/plugins/Makefile.am @@ -30,7 +30,7 @@ EXTRA_DIST = greedy2frame_template.c greedyh.asm \ # libpostproc is here so we can use their nice mangle.h AM_CFLAGS = -I$(top_srcdir)/src/post/deinterlace \ - -I$(top_srcdir)/src/libffmpeg/libavcodec/libpostproc + -I$(top_srcdir)/src/xine-utils # Avoid "can't find register" failures with -O0, -O2, -O3 (gcc 4.0) libdeinterlaceplugins_la-kdetv_greedyh.o libdeinterlaceplugins_la-kdetv_greedyh.lo: CFLAGS=$(shell echo @CFLAGS@ | sed -e 's/$$/ -O1/') diff --git a/src/post/deinterlace/plugins/tomsmocomp/tomsmocompmacros.h b/src/post/deinterlace/plugins/tomsmocomp/tomsmocompmacros.h index a3b92a51c..a0136fd44 100644 --- a/src/post/deinterlace/plugins/tomsmocomp/tomsmocompmacros.h +++ b/src/post/deinterlace/plugins/tomsmocomp/tomsmocompmacros.h @@ -2,6 +2,8 @@ #include #include +#include "mangle.h" + #define USE_FOR_DSCALER #define MyMemCopy xine_fast_memcpy diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am index 95de06b9e..a23ebe579 100644 --- a/src/xine-utils/Makefile.am +++ b/src/xine-utils/Makefile.am @@ -46,5 +46,5 @@ xineinclude_HEADERS = \ ring_buffer.h -noinst_HEADERS = ppcasm_string.h xine_check.h +noinst_HEADERS = ppcasm_string.h xine_check.h mangle.h diff --git a/src/xine-utils/mangle.h b/src/xine-utils/mangle.h new file mode 100644 index 000000000..7627ca2fc --- /dev/null +++ b/src/xine-utils/mangle.h @@ -0,0 +1,50 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * copyright (c) 2008 the xine-project + * + * This file is part of FFmpeg. + * + * 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 + */ + +/** + * @file + * + * @brief MANGLE definition from FFmpeg project, until the code is ported + * not to require this (considered an hack by the FFmpeg project. + */ + +#ifndef _XINE_MANGLE_H +#define _XINE_MANGLE_H + +// Use rip-relative addressing if compiling PIC code on x86-64. +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__DJGPP__) || \ + defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) +# if defined(__x86_64__) && defined(__PIC__) +# define MANGLE(a) "_" #a"(%%rip)" +# else +# define MANGLE(a) "_" #a +# endif +#else +# if defined(__x86_64__) && defined(__PIC__) +# define MANGLE(a) #a"(%%rip)" +# elif defined(__APPLE__) +# define MANGLE(a) "_" #a +# else +# define MANGLE(a) #a +# endif +#endif + +#endif -- cgit v1.2.3 From c96ecb56ab59611dbca40616566b159937dff958 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 2 Mar 2008 22:43:00 +0000 Subject: Reorganise DTS audio type detection (ready for LE16 & BE14); changelog entry. --- src/demuxers/demux_dts.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_dts.c b/src/demuxers/demux_dts.c index 2ea119858..c99a0688a 100644 --- a/src/demuxers/demux_dts.c +++ b/src/demuxers/demux_dts.c @@ -154,42 +154,48 @@ static int open_dts_file(demux_dts_t *this) { /* 16 bits and big endian bitstream */ if (syncword == 0x7ffe8001) { dts_version = 0; + break; } - /* 14 bits and little endian bitstream */ - if ((syncword == 0xff1f00e8) && - ((peak[i] & 0xf0) == 0xf0) && (peak[i+1] == 0x07)) { + else if ((syncword == 0xff1f00e8) && + ((peak[i] & 0xf0) == 0xf0) && (peak[i+1] == 0x07)) { dts_version = 3; - } - - if ( dts_version != -1 ) { - this->data_start = i-4; - lprintf("found DTS syncword at offset %d\n", i-4); - break; + break; } syncword = (syncword << 8) | peak[i]; } + if (dts_version == -1) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE ": unsupported DTS stream type, or not a DTS stream\n"); + return 0; + } + + this->data_start = i-4; + lprintf("found DTS syncword at offset %d\n", i-4); + if (i < peak_size-9) { unsigned int nblks, fsize, sfreq; - /* 16 bits and big endian bitstream */ - if (dts_version == 0) { + switch (dts_version) + { + case 0: /* BE16 */ nblks = ((peak[this->data_start+4] & 0x01) << 6) | ((peak[this->data_start+5] & 0xfc) >> 2); fsize = (((peak[this->data_start+5] & 0x03) << 12) |(peak[this->data_start+6] << 4) | ((peak[this->data_start+7] & 0xf0) >> 4)) + 1; sfreq = (peak[this->data_start+8] & 0x3c) >> 2; - } + break; - /* 14 bits and little endian bitstream */ - if (dts_version == 3) { + case 3: /* LE14 */ nblks = ((peak[this->data_start+4] & 0x07) << 4) | ((peak[this->data_start+7] & 0x3c) >> 2); fsize = (((peak[this->data_start+7] & 0x03) << 12) | (peak[this->data_start+6] << 4) | ((peak[this->data_start+9] & 0x3c) >> 2)) + 1; sfreq = peak[this->data_start+8] & 0x0f; + break; + } if ((sfreq > sizeof(dts_sample_rates)/sizeof(int)) || @@ -199,13 +205,16 @@ static int open_dts_file(demux_dts_t *this) { /* Big assumption - this is CBR data */ this->samples_per_frame = (nblks + 1) * 32; - /* 16 bits and big endian bitstream */ - if (dts_version == 0) { + switch (dts_version) + { + case 0: /* BE16 */ + case 1: /* LE16 */ this->frame_size = fsize * 8 / 16 * 2; - } - /* 14 bits and little endian bitstream */ - else if (dts_version == 3) { + break; + case 2: /* BE14 */ + case 3: /* LE14 */ this->frame_size = fsize * 8 / 14 * 2; + break; } this->sample_rate = dts_sample_rates[sfreq]; -- cgit v1.2.3 From d93c88ae06cd4452c8cfa5297def0f6e07c25fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 2 Mar 2008 18:57:51 +0100 Subject: Push out current frame when seeing the sequence end code 0xb7. --- src/libmpeg2/decode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libmpeg2/decode.c b/src/libmpeg2/decode.c index 58f34ccbc..c66b18691 100644 --- a/src/libmpeg2/decode.c +++ b/src/libmpeg2/decode.c @@ -461,9 +461,10 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code, break; case 0xb7: /* sequence end code */ -#ifdef LOG_PAN_SCAN - printf ("libmpeg2: sequence end code not handled\n"); -#endif + mpeg2_flush(mpeg2dec); + mpeg2dec->is_sequence_needed = 1; + break; + case 0xb8: /* group of pictures start code */ if (mpeg2_header_group_of_pictures (picture, buffer)) { printf ("libmpeg2: bad group of pictures\n"); -- cgit v1.2.3 From c3247cea37ea7702703826df6b68a9754f9b8984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 2 Mar 2008 20:24:27 +0100 Subject: Provide safe and convenient implementations of xine_get_current_frame(). xine_get_current_frame() relies on the caller to provide a sufficiently sized buffer. To calculate the required size of the buffer, one has to call xine_get_current_frame() to retrieve the necessary parameters. But as the image can change between two successive calls one has to pause the stream for consistency. To improve the situation, xine_get_current_frame_s() has been introduced which requires to specify the buffer size when an image is going to be retrieved. Furthermore, it will return the required/used buffer size. In that way, it can prevent copying data into a too small buffer and therefore can be considered safe. For convenience, xine_get_current_frame_alloc() is provided which takes care to allocate a sufficiently sized buffer. This function avoids pausing the stream as the image will be returned in a single call. --- src/xine-engine/xine.c | 74 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 0558f2f81..fb2c08b04 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -1915,11 +1915,12 @@ int xine_get_pos_length (xine_stream_t *stream, int *pos_stream, return 1; } -int xine_get_current_frame (xine_stream_t *stream, int *width, int *height, - int *ratio_code, int *format, - uint8_t *img) { +static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *height, + int *ratio_code, int *format, + uint8_t **img, int *size, int alloc_img) { vo_frame_t *frame; + int required_size; stream->xine->port_ticket->acquire(stream->xine->port_ticket, 0); frame = stream->video_out->get_last_frame (stream->video_out); @@ -1945,20 +1946,58 @@ int xine_get_current_frame (xine_stream_t *stream, int *width, int *height, *format = frame->format; - if (img){ + switch (*format) { + + case XINE_IMGFMT_YV12: + required_size = *width * *height + + ((*width + 1) / 2) * ((*height + 1) / 2) + + ((*width + 1) / 2) * ((*height + 1) / 2); + break; + + case XINE_IMGFMT_YUY2: + required_size = *width * *height + + ((*width + 1) / 2) * *height + + ((*width + 1) / 2) * *height; + break; + + default: + xprintf (stream->xine, XINE_VERBOSITY_DEBUG, + "xine: error, snapshot function not implemented for format 0x%x\n", frame->format); + _x_abort (); + } + + if (alloc_img) { + /* return size if requested */ + if (size) + *size = required_size; + /* allocate img or fail */ + if (!(*img = xine_xmalloc (required_size))) + return 0; + } else { + /* fail if supplied buffer is to small */ + if (*img && size && *size < required_size) { + *size = required_size; + return 0; + } + /* return size if requested */ + if (size) + *size = required_size; + } + + if (*img) { switch (frame->format) { case XINE_IMGFMT_YV12: yv12_to_yv12( /* Y */ frame->base[0], frame->pitches[0], - img, frame->width, + *img, frame->width, /* U */ frame->base[1], frame->pitches[1], - img+frame->width*frame->height, frame->width/2, + *img+frame->width*frame->height, frame->width/2, /* V */ frame->base[2], frame->pitches[2], - img+frame->width*frame->height+frame->width*frame->height/4, frame->width/2, + *img+frame->width*frame->height+frame->width*frame->height/4, frame->width/2, /* width x height */ frame->width, frame->height); break; @@ -1968,7 +2007,7 @@ int xine_get_current_frame (xine_stream_t *stream, int *width, int *height, /* src */ frame->base[0], frame->pitches[0], /* dst */ - img, frame->width*2, + *img, frame->width*2, /* width x height */ frame->width, frame->height); break; @@ -1982,6 +2021,25 @@ int xine_get_current_frame (xine_stream_t *stream, int *width, int *height, return 1; } +int xine_get_current_frame_alloc (xine_stream_t *stream, int *width, int *height, + int *ratio_code, int *format, + uint8_t **img, int *size) { + uint8_t *no_img = NULL; + return _x_get_current_frame_impl(stream, width, height, ratio_code, format, img ? img : &no_img, size, img != NULL); +} + +int xine_get_current_frame_s (xine_stream_t *stream, int *width, int *height, + int *ratio_code, int *format, + uint8_t *img, int *size) { + return (!img || size) && _x_get_current_frame_impl(stream, width, height, ratio_code, format, &img, size, 0); +} + +int xine_get_current_frame (xine_stream_t *stream, int *width, int *height, + int *ratio_code, int *format, + uint8_t *img) { + return _x_get_current_frame_impl(stream, width, height, ratio_code, format, &img, NULL, 0); +} + int xine_get_video_frame (xine_stream_t *stream, int timestamp, /* msec */ int *width, int *height, -- cgit v1.2.3 From c414377fbfa2be0577381c80dd0171061e242905 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 2 Mar 2008 22:16:08 +0000 Subject: Fix compilation with older external ffmpeg. HAVE_FFMPEG_AVUTIL_H wasn't being defined, and there were some incorrect checks. --- src/libffmpeg/ff_dvaudio_decoder.c | 2 +- src/libffmpeg/ff_video_decoder.c | 2 +- src/libffmpeg/ffmpeg_decoder.h | 2 +- src/post/planar/pp.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libffmpeg/ff_dvaudio_decoder.c b/src/libffmpeg/ff_dvaudio_decoder.c index a394e6615..5106a402c 100644 --- a/src/libffmpeg/ff_dvaudio_decoder.c +++ b/src/libffmpeg/ff_dvaudio_decoder.c @@ -52,7 +52,7 @@ # undef uint64_t #endif -#ifdef HAVE_FFMPEG_AVCODEC_H +#ifdef HAVE_FFMPEG_AVUTIL_H # include #else # include diff --git a/src/libffmpeg/ff_video_decoder.c b/src/libffmpeg/ff_video_decoder.c index d1d69416e..3d9c0225a 100644 --- a/src/libffmpeg/ff_video_decoder.c +++ b/src/libffmpeg/ff_video_decoder.c @@ -45,7 +45,7 @@ #include "ffmpeg_decoder.h" #include "ff_mpeg_parser.h" -#ifdef HAVE_FFMPEG_AVCODEC_H +#ifdef HAVE_FFMPEG_AVUTIL_H # include #else # include diff --git a/src/libffmpeg/ffmpeg_decoder.h b/src/libffmpeg/ffmpeg_decoder.h index adf0908dd..6de9e8772 100644 --- a/src/libffmpeg/ffmpeg_decoder.h +++ b/src/libffmpeg/ffmpeg_decoder.h @@ -25,7 +25,7 @@ #include "config.h" #endif -#ifdef HAVE_FFMPEG_AVCODEC_H +#ifdef HAVE_FFMPEG_AVUTIL_H # include #else # include diff --git a/src/post/planar/pp.c b/src/post/planar/pp.c index bc7cc1928..e658dadd0 100644 --- a/src/post/planar/pp.c +++ b/src/post/planar/pp.c @@ -25,7 +25,7 @@ #include "xineutils.h" #include -#ifdef HAVE_FFMPEG_AVCODEC_H +#ifdef HAVE_FFMPEG_AVUTIL_H # include #else # include -- cgit v1.2.3 From a574ab02526c78074f643971beebf2b86a3d16e6 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 4 Mar 2008 15:59:22 +0000 Subject: Fix libavcodec/dvdata.h-related build problems with older ffmpeg. --- src/combined/ffmpeg/Makefile.am | 2 +- src/combined/ffmpeg/ff_dvaudio_decoder.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/ffmpeg/Makefile.am b/src/combined/ffmpeg/Makefile.am index b9f0eac5c..3f8f6fa26 100644 --- a/src/combined/ffmpeg/Makefile.am +++ b/src/combined/ffmpeg/Makefile.am @@ -5,7 +5,7 @@ AM_CPPFLAGS = $(ZLIB_CPPFLAGS) AM_LDFLAGS = $(xineplug_ldflags) if WITH_EXTERNAL_FFMPEG -AM_CFLAGS += $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) +AM_CPPFLAGS += $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) else AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg diff --git a/src/combined/ffmpeg/ff_dvaudio_decoder.c b/src/combined/ffmpeg/ff_dvaudio_decoder.c index be7e8025f..7e285c115 100644 --- a/src/combined/ffmpeg/ff_dvaudio_decoder.c +++ b/src/combined/ffmpeg/ff_dvaudio_decoder.c @@ -54,6 +54,10 @@ #ifdef HAVE_FFMPEG_AVCODEC_H # include +# include +# define FFMPEG_AVCODEC_H +# define FFMPEG_RATIONAL_H +# define av_unused #else # include #endif -- cgit v1.2.3 From bcf7f94f2e1d901aa947ba621a917299ab251b83 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 4 Mar 2008 16:40:21 +0000 Subject: Whoops, managed to lose mangle.h. (This can happen when you revert & patch when merging.) --- src/xine-utils/mangle.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/xine-utils/mangle.h (limited to 'src') diff --git a/src/xine-utils/mangle.h b/src/xine-utils/mangle.h new file mode 100644 index 000000000..7627ca2fc --- /dev/null +++ b/src/xine-utils/mangle.h @@ -0,0 +1,50 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * copyright (c) 2008 the xine-project + * + * This file is part of FFmpeg. + * + * 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 + */ + +/** + * @file + * + * @brief MANGLE definition from FFmpeg project, until the code is ported + * not to require this (considered an hack by the FFmpeg project. + */ + +#ifndef _XINE_MANGLE_H +#define _XINE_MANGLE_H + +// Use rip-relative addressing if compiling PIC code on x86-64. +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__DJGPP__) || \ + defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) +# if defined(__x86_64__) && defined(__PIC__) +# define MANGLE(a) "_" #a"(%%rip)" +# else +# define MANGLE(a) "_" #a +# endif +#else +# if defined(__x86_64__) && defined(__PIC__) +# define MANGLE(a) #a"(%%rip)" +# elif defined(__APPLE__) +# define MANGLE(a) "_" #a +# else +# define MANGLE(a) #a +# endif +#endif + +#endif -- cgit v1.2.3 From e32eab57b9c6d869cdfa41b988e76184f2c5e41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 2 Mar 2008 21:33:15 +0100 Subject: Fix a compiler warning regarding const. --HG-- extra : transplant_source : %FFP%FFI%1EgE%7F%15%AAwQt%AD%08%FB6aO%19 --- src/vdr/input_vdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index 154bb9b56..863a2cc45 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -2039,7 +2039,7 @@ static char **vdr_class_get_autoplay_list(input_class_t *this_gen, vdr_input_class_t *class = (vdr_input_class_t *)this_gen; *num_files = 1; - return class->mrls; + return (char **)class->mrls; } void *vdr_input_init_plugin(xine_t *xine, void *data) -- cgit v1.2.3 From a33991c82965b1cf40c175b7bc9d13488e14cae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 2 Mar 2008 21:12:01 +0100 Subject: Fix "clear" implementation by introducing sync points in data stream. vdr-xine used a padding packet to push out any remaining data before input_vdr executed "clear" to drop that data. But depending on the way how input_vdr is connected to vdr-xine it could happen that the padding packet reached input_vdr after executing "clear" and therefore "clear" didn't work as expected. To fix this issue, sync points are introduced by making the padding packets "unique" in the stream. input_vdr will now drop all data up to the sync point packet. So even if the padding packet arrives later than the "clear" command, only data following the sync point will be fed to the demuxer. --HG-- extra : transplant_source : %A1%5E%8C%E1vmW%98D%1EW%A7%AF%B4V%5D%84%26%D0%DA --- src/vdr/input_vdr.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index 863a2cc45..32cef6395 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -111,6 +111,8 @@ typedef struct uint16_t image16_9_zoom_x; uint16_t image16_9_zoom_y; + uint8_t find_sync_point; + pthread_mutex_t find_sync_point_lock; } vdr_input_plugin_t; @@ -581,7 +583,13 @@ static off_t vdr_execute_rpc_command(vdr_input_plugin_t *this) int orig_speed = xine_get_param(this->stream, XINE_PARAM_FINE_SPEED); if (orig_speed <= 0) xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, XINE_FINE_SPEED_NORMAL); -fprintf(stderr, "+++ CLEAR(%d%c)\n", data->n, data->s ? 'b' : 'a'); +fprintf(stderr, "+++ CLEAR(%d%c): sync point: %02x\n", data->n, data->s ? 'b' : 'a', data->i); + if (!data->s) + { + pthread_mutex_lock(&this->find_sync_point_lock); + this->find_sync_point = data->i; + pthread_mutex_unlock(&this->find_sync_point_lock); + } /* if (!this->dont_change_xine_volume) xine_set_param(this->stream, XINE_PARAM_AUDIO_VOLUME, 0); @@ -1311,7 +1319,7 @@ static off_t vdr_plugin_read(input_plugin_t *this_gen, void *buf_gen, off_t len) { vdr_input_plugin_t *this = (vdr_input_plugin_t *) this_gen; - char *buf = (char *)buf_gen; + uint8_t *buf = (uint8_t *)buf_gen; off_t n, total; #ifdef LOG_READ lprintf ("reading %lld bytes...\n", len); @@ -1336,7 +1344,7 @@ static off_t vdr_plugin_read(input_plugin_t *this_gen, int retries = 0; do { - n = vdr_read_abort (this->stream, this->fh, &buf[total], len-total); + n = vdr_read_abort (this->stream, this->fh, (char *)&buf[total], len-total); if (0 == n) lprintf("read 0, retries: %d\n", retries); } @@ -1357,6 +1365,53 @@ static off_t vdr_plugin_read(input_plugin_t *this_gen, this->curpos += n; total += n; } + + if (this->find_sync_point + && total == 6) + { + pthread_mutex_lock(&this->find_sync_point_lock); + + while (this->find_sync_point + && total == 6 + && buf[0] == 0x00 + && buf[1] == 0x00 + && buf[2] == 0x01) + { + int l, sp; + + if (buf[3] == 0xbe + && buf[4] == 0xff) + { +//fprintf(stderr, "------- seen sync point: %02x, waiting for: %02x\n", buf[5], this->find_sync_point); + if (buf[5] == this->find_sync_point) + { + this->find_sync_point = 0; + break; + } + } + + if ((buf[3] & 0xf0) != 0xe0 + && (buf[3] & 0xe0) != 0xc0 + && buf[3] != 0xbd + && buf[3] != 0xbe) + { + break; + } + + l = buf[4] * 256 + buf[5]; + if (l <= 0) + break; + + sp = this->find_sync_point; + this->find_sync_point = 0; + this_gen->seek(this_gen, l, SEEK_CUR); + total = this_gen->read(this_gen, buf, 6); + this->find_sync_point = sp; + } + + pthread_mutex_unlock(&this->find_sync_point_lock); + } + return total; } @@ -1512,6 +1567,7 @@ static void vdr_plugin_dispose(input_plugin_t *this_gen) pthread_cond_destroy(&this->rpc_thread_shutdown_cond); pthread_mutex_destroy(&this->rpc_thread_shutdown_lock); + pthread_mutex_destroy(&this->find_sync_point_lock); pthread_mutex_destroy(&this->adjust_zoom_lock); if (this->fh_result != -1) @@ -2017,6 +2073,7 @@ static input_plugin_t *vdr_class_get_instance(input_class_t *cls_gen, xine_strea pthread_mutex_init(&this->rpc_thread_shutdown_lock, 0); pthread_cond_init(&this->rpc_thread_shutdown_cond, 0); + pthread_mutex_init(&this->find_sync_point_lock, 0); pthread_mutex_init(&this->adjust_zoom_lock, 0); this->image4_3_zoom_x = 0; this->image4_3_zoom_y = 0; -- cgit v1.2.3 From 1203bae5b93c837ecfd5a968cb1d67690d1af630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 2 Mar 2008 21:25:05 +0100 Subject: Intercept metronom to recognize discontinuities after which PTS is valid. For various operations, VDR needs to know the current PTS. But to have VDR work correctly, xine-lib's PTS must only be returned to vdr-xine when the PTS is related to the current stream. Intercepting the stream's metronom for monitoring discontinuities serves the need to detect the point in time from which on xine-lib's PTS values are related to the current stream. --HG-- extra : transplant_source : %89%DEe%F0uI%CCMK%27%9E%C3%A6%EC%ACk%13Bh%02 --- src/vdr/input_vdr.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index 32cef6395..6f0e204ac 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -61,7 +61,18 @@ */ +typedef struct vdr_input_plugin_s vdr_input_plugin_t; + typedef struct +{ + metronom_t metronom; + metronom_t *stream_metronom; + vdr_input_plugin_t *input; +} +vdr_metronom_t; + + +struct vdr_input_plugin_s { input_plugin_t input_plugin; @@ -113,9 +124,10 @@ typedef struct uint8_t find_sync_point; pthread_mutex_t find_sync_point_lock; -} -vdr_input_plugin_t; + vdr_metronom_t metronom; + int last_disc_type; +}; typedef struct @@ -1042,8 +1054,7 @@ fprintf(stderr, " result_get_pts.header.func = data->header.func; result_get_pts.header.len = sizeof (result_get_pts); - result_get_pts.pts = xine_get_current_vpts(this->stream) - this->stream->metronom->get_option(this->stream->metronom, METRONOM_VPTS_OFFSET); - + result_get_pts.pts = (this->last_disc_type == DISC_STREAMSTART) ? -2 : (xine_get_current_vpts(this->stream) - this->stream->metronom->get_option(this->stream->metronom, METRONOM_VPTS_OFFSET)); if (sizeof (result_get_pts) != vdr_write(this->fh_result, &result_get_pts, sizeof (result_get_pts))) return -1; } @@ -1595,6 +1606,10 @@ static void vdr_plugin_dispose(input_plugin_t *this_gen) close(this->fh); free(this->mrl); + + this->stream->metronom = this->metronom.stream_metronom; + this->metronom.stream_metronom = 0; + free(this); } @@ -2002,6 +2017,69 @@ static void event_handler(void *user_data, const xine_event_t *event) _("%s: input event write: %s.\n"), LOG_MODULE, strerror(errno)); } + +static void vdr_metronom_set_audio_rate(metronom_t *self, int64_t pts_per_smpls) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + this->stream_metronom->set_audio_rate(this->stream_metronom, pts_per_smpls); +} + +static void vdr_metronom_got_video_frame(metronom_t *self, vo_frame_t *frame) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + this->stream_metronom->got_video_frame(this->stream_metronom, frame); +} + +static int64_t vdr_metronom_got_audio_samples(metronom_t *self, int64_t pts, int nsamples) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + return this->stream_metronom->got_audio_samples(this->stream_metronom, pts, nsamples); +} + +static int64_t vdr_metronom_got_spu_packet(metronom_t *self, int64_t pts) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + return this->stream_metronom->got_spu_packet(this->stream_metronom, pts); +} + +static void vdr_metronom_handle_audio_discontinuity(metronom_t *self, int type, int64_t disc_off) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + this->stream_metronom->handle_audio_discontinuity(this->stream_metronom, type, disc_off); + this->input->last_disc_type = type; +} + +static void vdr_metronom_handle_video_discontinuity(metronom_t *self, int type, int64_t disc_off) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + this->stream_metronom->handle_video_discontinuity(this->stream_metronom, type, disc_off); + this->input->last_disc_type = type; +} + +static void vdr_metronom_set_option(metronom_t *self, int option, int64_t value) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + this->stream_metronom->set_option(this->stream_metronom, option, value); +} + +static int64_t vdr_metronom_get_option(metronom_t *self, int option) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + return this->stream_metronom->get_option(this->stream_metronom, option); +} + +static void vdr_metronom_set_master(metronom_t *self, metronom_t *master) +{ + vdr_metronom_t *this = (vdr_metronom_t *)self; + this->stream_metronom->set_master(this->stream_metronom, master); +} + +static void vdr_metronom_exit(metronom_t *self) +{ + _x_abort(); +} + + static input_plugin_t *vdr_class_get_instance(input_class_t *cls_gen, xine_stream_t *stream, const char *data) { @@ -2084,6 +2162,21 @@ static input_plugin_t *vdr_class_get_instance(input_class_t *cls_gen, xine_strea if (this->event_queue) xine_event_create_listener_thread(this->event_queue, event_handler, this); + this->metronom.input = this; + this->metronom.metronom.set_audio_rate = vdr_metronom_set_audio_rate; + this->metronom.metronom.got_video_frame = vdr_metronom_got_video_frame; + this->metronom.metronom.got_audio_samples = vdr_metronom_got_audio_samples; + this->metronom.metronom.got_spu_packet = vdr_metronom_got_spu_packet; + this->metronom.metronom.handle_audio_discontinuity = vdr_metronom_handle_audio_discontinuity; + this->metronom.metronom.handle_video_discontinuity = vdr_metronom_handle_video_discontinuity; + this->metronom.metronom.set_option = vdr_metronom_set_option; + this->metronom.metronom.get_option = vdr_metronom_get_option; + this->metronom.metronom.set_master = vdr_metronom_set_master; + this->metronom.metronom.exit = vdr_metronom_exit; + + this->metronom.stream_metronom = stream->metronom; + stream->metronom = &this->metronom.metronom; + return &this->input_plugin; } -- cgit v1.2.3 From 6609e9267187111e7ba78dad0b9049cafdaebc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 2 Mar 2008 21:29:41 +0100 Subject: Make use of the new function xine_get_current_frame_alloc(). The new function allows us to remove pausing the stream as the image data can now be retrieved in a single call. --HG-- extra : transplant_source : %DE%A7%7B%C9%E93%15%AC%1E%3D%A2Ik%E4%D1%AC44w_ --- src/vdr/input_vdr.c | 51 ++++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index 6f0e204ac..48cc74aed 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -972,33 +972,9 @@ fprintf(stderr, " int height = 0; int ratio_code = 0; int format = 0; - - int orig_speed = xine_get_param(this->stream, XINE_PARAM_FINE_SPEED); - if (XINE_SPEED_PAUSE != orig_speed) - xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, XINE_SPEED_PAUSE); - - if (xine_get_current_frame(this->stream, &width, &height, &ratio_code, &format, 0)) + + if (xine_get_current_frame_alloc(this->stream, &width, &height, &ratio_code, &format, &img, &frame_size)) { - switch (format) - { - case XINE_IMGFMT_YV12: - frame_size = width * height - + ((width + 1) / 2) * ((height + 1) / 2) - + ((width + 1) / 2) * ((height + 1) / 2); - break; - - case XINE_IMGFMT_YUY2: - frame_size = width * height - + ((width + 1) / 2) * height - + ((width + 1) / 2) * height; - break; - } - - img = xine_xmalloc(frame_size); - - if (!xine_get_current_frame(this->stream, &width, &height, &ratio_code, &format, img)) - frame_size = 0; - if (ratio_code == XINE_VO_ASPECT_SQUARE) ratio_code = 10000; else if (ratio_code == XINE_VO_ASPECT_4_3) @@ -1007,17 +983,15 @@ fprintf(stderr, " ratio_code = 17778; else if (ratio_code == XINE_VO_ASPECT_DVB) ratio_code = 21100; - - if (0 == frame_size) - { - width = 0; - height = 0; - ratio_code = 0; - } } - - if (XINE_SPEED_PAUSE != orig_speed) - xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, orig_speed); + + if (!img) + { + frame_size = 0, + width = 0; + height = 0; + ratio_code = 0; + } { result_grab_image_t result_grab_image; @@ -1031,13 +1005,12 @@ fprintf(stderr, " if (sizeof (result_grab_image) == vdr_write(this->fh_result, &result_grab_image, sizeof (result_grab_image))) { - if (frame_size == vdr_write(this->fh_result, img, frame_size)) + if (!frame_size || (frame_size == vdr_write(this->fh_result, img, frame_size))) ret_val = 0; } } - if (img) - free(img); + free(img); if (ret_val != 0) return ret_val; -- cgit v1.2.3 From fbd93b493f7c694e1c750b110ded431a65cb9664 Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Fri, 14 Mar 2008 20:05:34 +0000 Subject: Unportable pthread_t compare in xine.c With Pthreads for Win32/Win64 I cannot compare two pthread_t items because they are implemented as structures. This patch fixes the comparison by using pthread_equal() function. --HG-- extra : transplant_source : %9D%98%CE%83%5E%BD%A9u%11%C7%3BmP%28%EBH%D0%B6I%DF --- src/xine-engine/xine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index c207680e6..efb845be5 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -133,7 +133,7 @@ static int acquire_allowed_to_block(xine_ticket_t *this) { unsigned new_size; for(entry = 0; entry < this->holder_thread_count; ++entry) { - if(this->holder_threads[entry].holder == own_id) { + if(pthread_equal(this->holder_threads[entry].holder, own_id)) { /* This thread may already hold this ticket */ this->holder_threads[entry].count++; return (this->holder_threads[entry].count == 1); @@ -204,7 +204,7 @@ static int release_allowed_to_block(xine_ticket_t *this) { unsigned entry; for(entry = 0; entry < this->holder_thread_count; ++entry) { - if(this->holder_threads[entry].holder == own_id) { + if(pthread_equal(this->holder_threads[entry].holder, own_id)) { this->holder_threads[entry].count--; return this->holder_threads[entry].count == 0; } -- cgit v1.2.3 From b23f7d232b98527846bfcd41aed36914ffbc431b Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Fri, 14 Mar 2008 20:13:48 +0000 Subject: xine_init(): mutex objs not initialized The problem comes from the fact that into xine_probe_fast_memcpy() there is a call to xprintf, which excutes some actions to this->log_lock. But the "log_lock" field is still uninitialized. Under Windows, the xine_init() always crashes because that type is implemented as a structure, so the lock receives a NULL pointer and the execution is halted. The attached patch proposes to move the mutex objects to the top of xine_init() function. --HG-- extra : transplant_source : %07%1D%7F%F0%97%7D%06%3E%9F%2Ar%03%1DQ%14%F3%D1%EF%1D%93 --- src/xine-engine/xine.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index efb845be5..d58b4ea55 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -1662,6 +1662,12 @@ void xine_init (xine_t *this) { static const char *demux_strategies[] = {"default", "reverse", "content", "extension", NULL}; + /* + * locks + */ + pthread_mutex_init (&this->streams_lock, NULL); + pthread_mutex_init (&this->log_lock, NULL); + /* initialize color conversion tables and functions */ init_yuv_conversion(); @@ -1742,12 +1748,6 @@ void xine_init (xine_t *this) { */ this->streams = xine_list_new(); - /* - * locks - */ - pthread_mutex_init (&this->streams_lock, NULL); - pthread_mutex_init (&this->log_lock, NULL); - /* * start metronom clock */ -- cgit v1.2.3 From bfcacf9ccf8331baf47a7db55017d0ca5e273080 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 17 Mar 2008 16:01:40 +0000 Subject: Allow CR & LF termination of XML element names. --- src/xine-utils/xmllexer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index be3bdd248..09e5a5e24 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -411,6 +411,8 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case '\"': /* " */ case ' ': case '\t': + case '\n': + case '\r': case '=': case '/': tok[tok_pos] = '\0'; -- cgit v1.2.3 From 431033df2571df5bdd1ec1253cf04921b6d01368 Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Sun, 2 Mar 2008 22:48:39 +0000 Subject: libdvdread - Uses UDF provided length as authoritative libdvdread uses the file length provided by the UDF fs of the title set IFO files authoritative. I got a DVD which have parts of this file mapped outside of the provided file size and according to my memory only the offsets in the files matters in the standard. This patch adjusts the internal knowledge of the filesize accordingly and at least allows mplayer to play the dvd. (Imported from Debian libdvdread 0.9.7-8) --- src/input/libdvdnav/dvd_reader.c | 24 +++++++++++++++++++++++- src/input/libdvdnav/dvd_reader.h | 2 ++ src/input/libdvdnav/ifo_read.c | 6 +++++- 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/input/libdvdnav/dvd_reader.c b/src/input/libdvdnav/dvd_reader.c index 200a1dbec..eff1977fc 100644 --- a/src/input/libdvdnav/dvd_reader.c +++ b/src/input/libdvdnav/dvd_reader.c @@ -1037,6 +1037,28 @@ int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset ) return offset; } +int32_t DVDFileSeekForce( dvd_file_t *dvd_file, int offset, int force_size ) +{ + /* Check arguments. */ + if( dvd_file == NULL || offset < 0 ) + return -1; + + if( dvd_file->dvd->isImageFile ) { + if( force_size < 0 ) + force_size = (offset - 1) / DVD_VIDEO_LB_LEN + 1; + if( dvd_file->filesize < force_size) { + dvd_file->filesize = force_size; + fprintf(stderr, "libdvdread: Ignored UDF provided size of file.\n"); + } + } + + if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) { + return -1; + } + dvd_file->seek_pos = (uint32_t) offset; + return offset; +} + ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size ) { unsigned char *secbuf_base, *secbuf; @@ -1077,7 +1099,7 @@ ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size ) memcpy( data, &(secbuf[ seek_byte ]), byte_size ); free( secbuf_base ); - dvd_file->seek_pos += byte_size; + DVDFileSeekForce(dvd_file, dvd_file->seek_pos + byte_size, -1); return byte_size; } diff --git a/src/input/libdvdnav/dvd_reader.h b/src/input/libdvdnav/dvd_reader.h index bb3f5053b..e1b051c00 100644 --- a/src/input/libdvdnav/dvd_reader.h +++ b/src/input/libdvdnav/dvd_reader.h @@ -171,6 +171,8 @@ ssize_t DVDReadBlocks( dvd_file_t *, int, size_t, unsigned char * ); */ int32_t DVDFileSeek( dvd_file_t *, int32_t ); +int32_t DVDFileSeekForce( dvd_file_t *, int, int ); + /** * Reads the given number of bytes from the file. This call can only be used * on the information files, and may not be used for reading from a VOB. This diff --git a/src/input/libdvdnav/ifo_read.c b/src/input/libdvdnav/ifo_read.c index 8f47d2a54..bc1ba580b 100644 --- a/src/input/libdvdnav/ifo_read.c +++ b/src/input/libdvdnav/ifo_read.c @@ -93,6 +93,10 @@ static inline int DVDFileSeek_( dvd_file_t *dvd_file, uint32_t offset ) { return (DVDFileSeek(dvd_file, (int)offset) == (int)offset); } +static inline int32_t DVDFileSeekForce_( dvd_file_t *dvd_file, uint32_t offset, int force_size ) { + return (DVDFileSeekForce(dvd_file, (int)offset, force_size) == (int)offset); +} + ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) { ifo_handle_t *ifofile; @@ -1507,7 +1511,7 @@ static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, unsigned int i; int info_length; - if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) + if(!DVDFileSeekForce_(ifofile->file, sector * DVD_BLOCK_LEN, sector)) return 0; if(!(DVDReadBytes(ifofile->file, vobu_admap, VOBU_ADMAP_SIZE))) -- cgit v1.2.3 From c1d4212fe2fa0f85246e47505b6887e66884cb6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Thu, 6 Mar 2008 20:24:44 +0100 Subject: Fix _x_get_current_frame_impl() to not abort when used legally. Retrieving frame size and format is a legal operation even for otherwise not supported frame formats like XXMC. --- src/xine-engine/xine.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index fb2c08b04..e9251267b 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -1961,9 +1961,13 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he break; default: + if (*img || alloc_img) { xprintf (stream->xine, XINE_VERBOSITY_DEBUG, "xine: error, snapshot function not implemented for format 0x%x\n", frame->format); _x_abort (); + } + + required_size = 0; } if (alloc_img) { -- cgit v1.2.3 From 24ac3c3cd129ceb6e181e9f36c2ade5e3ec82cc4 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 6 Mar 2008 14:16:09 +0000 Subject: CVS broken with built-in ffmpeg I can no longer build libxine from CVS, unless I apply this patch. I do not have ffmpeg installed, and so am using the built-in ffmpeg instead (I think). --HG-- extra : transplant_source : %96v8%CE%21%82%CCh%0A%83%0C%BC%C5%91F%89W%E4%B8%AE --- src/libffmpeg/Makefile.am | 2 +- src/post/planar/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am index 96d269278..d2be74c39 100644 --- a/src/libffmpeg/Makefile.am +++ b/src/libffmpeg/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/misc/Makefile.common -DEFAULT_INCLUDES = -I. +DEFAULT_INCLUDES = -I. -Ilibavcodec if HAVE_FFMPEG AM_CFLAGS = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) diff --git a/src/post/planar/Makefile.am b/src/post/planar/Makefile.am index 4ba6bfa41..36405bfc2 100644 --- a/src/post/planar/Makefile.am +++ b/src/post/planar/Makefile.am @@ -6,7 +6,7 @@ if HAVE_FFMPEG postproc_lib = $(FFMPEG_POSTPROC_LIBS) ff_cflags = $(FFMPEG_POSTPROC_CFLAGS) else -ff_cflags = -I$(top_srcdir)/src/libffmpeg/libavcodec/libpostproc +ff_cflags = -I$(top_srcdir)/src/libffmpeg/libavcodec postproc_lib = $(POSTPROC_INT_LIB) postproc_dep = $(postproc_lib) endif -- cgit v1.2.3 From ae651aa3b87d83e4b1e7f24590241b4459a8d4b4 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 6 Mar 2008 21:56:01 +0000 Subject: Fix include path to internal ffmpeg for post/planar --- src/post/planar/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/post/planar/Makefile.am b/src/post/planar/Makefile.am index cb1ee68f9..8caffc6b9 100644 --- a/src/post/planar/Makefile.am +++ b/src/post/planar/Makefile.am @@ -8,7 +8,7 @@ if WITH_EXTERNAL_FFMPEG postproc_lib = $(FFMPEG_POSTPROC_LIBS) ff_cflags = $(FFMPEG_POSTPROC_CFLAGS) else -AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg/libpostproc +AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg/ postproc_lib = $(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a \ $(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a -- cgit v1.2.3 From e6f87e34ee65c805bde5805f89ac362095e9df4c Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 6 Mar 2008 21:59:28 +0000 Subject: Fix compilation for installed libintl.h in include paths Compilation of xine-lib-1.2 hg failed for me as libintl.h does this: #define textdomain libintl_textdomain This causes trouble accessing fields in structures which are accidentally named "textdomain". The patch renames textdomain to text_domain in xine headers and xine- engine/xine.c and xine/load_plugins.c --- src/xine-engine/load_plugins.c | 2 +- src/xine-engine/xine.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 8e4a10a60..46535ef33 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -2403,7 +2403,7 @@ const char *const *xine_list_post_plugins_typed(xine_t *xine, uint32_t type) { else \ return NULL; \ } \ - return dgettext(ic->textdomain ? : XINE_TEXTDOMAIN, ic->description); \ + return dgettext(ic->text_domain ? : XINE_TEXTDOMAIN, ic->description); \ } \ } \ return NULL; \ diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 16d39b2b0..18a9e8e9f 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -885,7 +885,7 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { int res; xine_log (stream->xine, XINE_LOG_MSG, _("xine: found input plugin : %s\n"), - dgettext(stream->input_plugin->input_class->textdomain ? : XINE_TEXTDOMAIN, + dgettext(stream->input_plugin->input_class->text_domain ? : XINE_TEXTDOMAIN, stream->input_plugin->input_class->description)); if (stream->input_plugin->input_class->eject_media) stream->eject_class = stream->input_plugin->input_class; @@ -1235,7 +1235,7 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { } xine_log (stream->xine, XINE_LOG_MSG, _("xine: found demuxer plugin: %s\n"), - dgettext(stream->demux_plugin->demux_class->textdomain ? : XINE_TEXTDOMAIN, + dgettext(stream->demux_plugin->demux_class->text_domain ? : XINE_TEXTDOMAIN, stream->demux_plugin->demux_class->description)); _x_extra_info_reset( stream->current_extra_info ); -- cgit v1.2.3 From 3d745bde9e0ad2f3097f3934562c85093eeaa2ff Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 6 Mar 2008 22:01:03 +0000 Subject: Fix compilation of video_macosx.m video_macosx.m was not update to specify includes and default_video_driver_class was not renamed to default_video_driver_class_dispose --- src/video_out/video_out_macosx.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/video_out/video_out_macosx.m b/src/video_out/video_out_macosx.m index 9c65d579d..70cffaeb8 100644 --- a/src/video_out/video_out_macosx.m +++ b/src/video_out/video_out_macosx.m @@ -36,11 +36,11 @@ #define LOG */ -#include "video_out.h" -#include "vo_scale.h" #include "xine.h" -#include "xine_internal.h" -#include "xineutils.h" +#include "xine/video_out.h" +#include "xine/vo_scale.h" +#include "xine/xine_internal.h" +#include "xine/xineutils.h" #include "macosx/video_window.h" @@ -358,7 +358,7 @@ static void *init_class (xine_t *xine, void *visual) { this->driver_class.open_plugin = open_plugin; this->driver_class.identifier = "MacOSX"; this->driver_class.description = N_("xine video output plugin for Mac OS X"); - this->driver_class.dispose = default_video_driver_class; + this->driver_class.dispose = default_video_driver_class_dispose; this->config = xine->config; this->xine = xine; -- cgit v1.2.3 From 567a45c982f7806344426cb5495e429ab80793a3 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 6 Mar 2008 23:03:53 +0000 Subject: Fix DXR3 build with internal/new ffmpeg. --- src/combined/ffmpeg/ffmpeg_encoder.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/ffmpeg/ffmpeg_encoder.c b/src/combined/ffmpeg/ffmpeg_encoder.c index 7fe65c7fa..c1e3d2823 100644 --- a/src/combined/ffmpeg/ffmpeg_encoder.c +++ b/src/combined/ffmpeg/ffmpeg_encoder.c @@ -38,7 +38,11 @@ #include "video_out_dxr3.h" -#include +#ifdef HAVE_FFMPEG_AVUTIL_H +# include +#else +# include +#endif /* buffer size for encoded mpeg1 stream; will hold one intra frame * at 640x480 typical sizes are <50 kB. 512 kB should be plenty */ -- cgit v1.2.3 From 118e60d2017ea780f68b959718f7fea1f829ab9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Thu, 6 Mar 2008 20:03:31 +0100 Subject: Fix deadlock in sync point code caused by initial handshake byte. --HG-- extra : transplant_source : %09%A1%828%A2%19P%09%A0%D7%83%DB.%B3%D2%13%26%7D%10%DC --- src/vdr/input_vdr.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index 48cc74aed..ade2ecfa1 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -1652,6 +1652,12 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) fcntl(this->fh, F_SETFL, ~O_NONBLOCK & fcntl(this->fh, F_GETFL, 0)); + /* eat initial handshake byte */ + { + char b; + read(this->fh, &b, 1); + } + { char *filename_control = 0; asprintf(&filename_control, "%s.control", filename); -- cgit v1.2.3 From 356d5df6bc31057df6b676a294aadc40de82b1da Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 7 Mar 2008 15:48:56 +0000 Subject: Get rid of some "may be used uninitialised" warnings. --- src/demuxers/asfheader.c | 14 +++++++------- src/demuxers/demux_ogg.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index eb74c0886..f95c68e41 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -399,7 +399,7 @@ static int asf_header_parse_stream_extended_properties(asf_header_t *header, uin if (asf_stream_extension->stream_name_count) { asf_stream_extension->stream_names = malloc (asf_stream_extension->stream_name_count * sizeof(void*)); for (i = 0; i < asf_stream_extension->stream_name_count; i++) { - uint16_t lang_index, length; + uint16_t lang_index, length = 0; asf_reader_get_16(&reader, &lang_index); asf_reader_get_16(&reader, &length); asf_stream_extension->stream_names[i] = (char*)asf_reader_get_bytes(&reader, length); /* store them */ @@ -411,7 +411,7 @@ static int asf_header_parse_stream_extended_properties(asf_header_t *header, uin for (i = 0; i < asf_stream_extension->payload_extension_system_count; i++) { GUID guid; uint16_t data_size; - uint32_t length; + uint32_t length = 0; asf_reader_get_guid(&reader, &guid); asf_reader_get_16(&reader, &data_size); asf_reader_get_32(&reader, &length); @@ -427,7 +427,7 @@ static int asf_header_parse_stream_extended_properties(asf_header_t *header, uin /* embeded stream properties */ if (asf_reader_get_size(&reader) >= 24) { GUID guid; - uint64_t object_length; + uint64_t object_length = 0; asf_reader_get_guid(&reader, &guid); asf_reader_get_64(&reader, &object_length); @@ -490,8 +490,8 @@ static int asf_header_parse_stream_bitrate_properties(asf_header_t *header_pub, lprintf (" bitrate count: %d\n", bitrate_count); for(i = 0; i < bitrate_count; i++) { - uint16_t flags; - uint32_t bitrate; + uint16_t flags = 0; + uint32_t bitrate = 0; int stream_number; uint8_t *bitrate_pointer; @@ -533,7 +533,7 @@ static int asf_header_parse_header_extension(asf_header_t *header, uint8_t *buff GUID guid; int object_id; - uint64_t object_length, object_data_length; + uint64_t object_length = 0, object_data_length; if (asf_reader_get_size(&reader) < 24) { printf("invalid buffer size\n"); @@ -644,7 +644,7 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { GUID guid; int object_id; - uint64_t object_length, object_data_length; + uint64_t object_length = 0, object_data_length; if (asf_reader_get_size(&reader) < 24) { printf("invalid buffer size\n"); diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index dc867e5f1..175d61cd8 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -1194,7 +1194,7 @@ static void decode_theora_header (demux_ogg_t *this, const int stream_num, ogg_p 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; + xine_flac_streaminfo_block streaminfo = {}; buf_element_t *buf; xine_waveformatex wave; -- cgit v1.2.3 From 925407b099b381f2cd5137b82e92b864e63eca5c Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 10 Mar 2008 00:06:48 -0300 Subject: Support # stream parameter separator in raw filenames as well as in full MRLs. Changeset 8ffe18290ba5 fixed bug 1784272 (opening raw filenames with # character, like "show #1.mpg") but at the cost of killing # separator in raw filenames completely. Although this might be a valid requirement in a new devel branch, imho, such change in stable branch should be considered a regression. The original idea of passing partial MRL for the input plugins to try doesn't work because plugin will generate error messages for every failed attempt to open the file (like "show " above), even thought the complete MRL is valid and will be played. So, since raw filenames are an exception for the MRL scheme anyway, we try stat'ing the partial filenames to determine what user means with the #. --- src/xine-engine/xine.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index e9251267b..841f966d1 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -36,6 +36,7 @@ #include #include #include +#include #if defined (__linux__) || defined (__GLIBC__) #include #elif defined (__FreeBSD__) @@ -796,6 +797,7 @@ static inline int _x_path_looks_like_mrl (const char *path) /*static*/ int open_internal (xine_stream_t *stream, const char *mrl) { const char *stream_setup = NULL; + const char *mrl_proto = NULL; int no_cache = 0; if (!mrl) { @@ -819,16 +821,31 @@ static inline int _x_path_looks_like_mrl (const char *path) /* * look for a stream_setup in MRL and try finding an input plugin */ + stream_setup = strchr (mrl, '#'); if (isalpha (*mrl)) { - stream_setup = mrl + 1; - while (isalnum (*stream_setup) || *stream_setup == '+' || *stream_setup == '-' || *stream_setup == '.') - ++stream_setup; - if (stream_setup[0] == ':' && stream_setup[1] == '/') - stream_setup = strchr (mrl, '#'); - else - stream_setup = NULL; + mrl_proto = mrl + 1; + while (isalnum (*mrl_proto) || *mrl_proto == '+' || *mrl_proto == '-' || *mrl_proto == '.') + ++mrl_proto; + if (!mrl_proto[0] || mrl_proto[0] != ':' || mrl_proto[1] != '/') + mrl_proto = NULL; + } + + /* for raw filenames we must try every '#' checking if it is part of the filename */ + if( !mrl_proto && stream_setup) { + struct stat stat_buf; + int res; + + while( stream_setup ) { + char *raw_filename = strndup (mrl, stream_setup - mrl); + + res = stat(raw_filename, &stat_buf); + free(raw_filename); + if( !res ) + break; + stream_setup = strchr(stream_setup + 1, '#'); + } } { @@ -837,8 +854,10 @@ static inline int _x_path_looks_like_mrl (const char *path) /* * find an input plugin */ - - if ((stream->input_plugin = _x_find_input_plugin (stream, input_source))) { + stream->input_plugin = _x_find_input_plugin (stream, input_source); + free(input_source); + + if ( stream->input_plugin ) { int res; xine_log (stream->xine, XINE_LOG_MSG, _("xine: found input plugin : %s\n"), @@ -853,7 +872,6 @@ static inline int _x_path_looks_like_mrl (const char *path) case 1: /* Open successfull */ break; case -1: /* Open unsuccessfull, but correct plugin */ - free(input_source); stream->err = XINE_ERROR_INPUT_FAILED; _x_flush_events_queues (stream); return 0; @@ -864,8 +882,6 @@ static inline int _x_path_looks_like_mrl (const char *path) stream->err = XINE_ERROR_INPUT_FAILED; } } - - free(input_source); } if (!stream->input_plugin) { -- cgit v1.2.3 From 6e14bdb6a55f5136fa0e99b2b9b621647fc7d432 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 10 Mar 2008 18:19:09 +0000 Subject: Add Xv port selection by type (overlay or textured video). This uses the adapter names reported by the X 2D graphics driver. --HG-- extra : transplant_source : %AE%87%B0%EAy%A0%DEXJ%8D6f%EA%C6iw%F0%03%60%29 --- src/video_out/video_out_xcbxv.c | 23 ++++++++++++++++++----- src/video_out/video_out_xv.c | 22 +++++++++++++++++----- src/video_out/video_out_xxmc.c | 21 ++++++++++++++++----- src/video_out/xv_common.h | 11 +++++++++++ 4 files changed, 62 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index d77917a70..e267f98fb 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -151,6 +151,8 @@ typedef struct { xine_t *xine; } xv_class_t; +static const char *const prefer_types[] = VIDEO_DEVICE_XV_PREFER_TYPES; + static uint32_t xv_get_capabilities (vo_driver_t *this_gen) { xv_driver_t *this = (xv_driver_t *) this_gen; @@ -1145,10 +1147,15 @@ xv_find_adaptor_by_port (int port, xcb_xv_adaptor_info_iterator_t *adaptor_it) static xcb_xv_port_t xv_autodetect_port(xv_driver_t *this, xcb_xv_adaptor_info_iterator_t *adaptor_it, - xcb_xv_port_t base) + xcb_xv_port_t base, + xv_prefertype prefer_type) { + xcb_xv_adaptor_info_iterator_t *start = adaptor_it; + for (; adaptor_it->rem; xcb_xv_adaptor_info_next(adaptor_it)) - if (adaptor_it->data->type & XCB_XV_TYPE_IMAGE_MASK) + if (adaptor_it->data->type & XCB_XV_TYPE_IMAGE_MASK && + (prefer_type == xv_prefer_none || + strcasestr (xcb_xv_adaptor_info_name (adaptor_it->data), prefer_types[prefer_type]))) { int j; for (j = 0; j < adaptor_it->data->num_ports; ++j) @@ -1168,6 +1175,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis int i; xcb_visual_t *visual = (xcb_visual_t *) visual_gen; xcb_xv_port_t xv_port; + xv_prefertype prefer_type; const xcb_query_extension_reply_t *query_extension_reply; @@ -1219,19 +1227,24 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis adaptor_it = xcb_xv_query_adaptors_info_iterator(query_adaptors_reply); xv_port = config->register_num (config, "video.device.xv_port", 0, VIDEO_DEVICE_XV_PORT_HELP, - 10, NULL, NULL); + 20, NULL, NULL); + prefer_type = config->register_enum (config, "video.device.xv_preferred_method", 0, + prefer_types, VIDEO_DEVICE_XV_PREFER_TYPE_HELP, + 10, NULL, NULL); if (xv_port != 0) { if (! xv_open_port(this, xv_port)) { xprintf(class->xine, XINE_VERBOSITY_NONE, _("%s: could not open Xv port %d - autodetecting\n"), LOG_MODULE, xv_port); - xv_port = xv_autodetect_port (this, &adaptor_it, xv_port); + xv_port = xv_autodetect_port (this, &adaptor_it, xv_port, prefer_type); } else xv_find_adaptor_by_port (xv_port, &adaptor_it); } if (!xv_port) - xv_port = xv_autodetect_port (this, &adaptor_it, 0); + xv_port = xv_autodetect_port (this, &adaptor_it, 0, prefer_type); + if (!xv_port) + xv_port = xv_autodetect_port (this, &adaptor_it, 0, xv_prefer_none); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index a874e4cdf..0026bd8af 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -164,6 +164,8 @@ typedef struct { static int gX11Fail; +static const char *const prefer_types[] = VIDEO_DEVICE_XV_PREFER_TYPES; + static uint32_t xv_get_capabilities (vo_driver_t *this_gen) { xv_driver_t *this = (xv_driver_t *) this_gen; @@ -1178,11 +1180,15 @@ static XvPortID xv_autodetect_port(xv_driver_t *this, unsigned int adaptors, XvAdaptorInfo *adaptor_info, unsigned int *adaptor_num, - XvPortID base) { + XvPortID base, + xv_prefertype prefer_type) +{ unsigned int an, j; for (an = 0; an < adaptors; an++) - if (adaptor_info[an].type & XvImageMask) + if (adaptor_info[an].type & XvImageMask && + (prefer_type == xv_prefer_none || + strcasestr (adaptor_info[an].name, prefer_types[prefer_type]))) for (j = 0; j < adaptor_info[an].num_ports; j++) { XvPortID port = adaptor_info[an].base_id + j; if (port >= base && xv_open_port(this, port)) { @@ -1212,6 +1218,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * XvPortID xv_port; XvAdaptorInfo *adaptor_info; unsigned int adaptor_num; + xv_prefertype prefer_type; this = (xv_driver_t *) xine_xmalloc (sizeof (xv_driver_t)); if (!this) @@ -1251,19 +1258,24 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * xv_port = config->register_num (config, "video.device.xv_port", 0, VIDEO_DEVICE_XV_PORT_HELP, - 10, NULL, NULL); + 20, NULL, NULL); + prefer_type = config->register_enum (config, "video.device.xv_preferred_method", 0, + prefer_types, VIDEO_DEVICE_XV_PREFER_TYPE_HELP, + 10, NULL, NULL); if (xv_port != 0) { if (! xv_open_port(this, xv_port)) { xprintf(class->xine, XINE_VERBOSITY_NONE, _("%s: could not open Xv port %d - autodetecting\n"), LOG_MODULE, xv_port); - xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, xv_port); + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, xv_port, prefer_type); } else adaptor_num = xv_find_adaptor_by_port (xv_port, adaptors, adaptor_info); } if (!xv_port) - xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0); + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0, prefer_type); + if (!xv_port) + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0, xv_prefer_none); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index 1ef3652a9..bd8a76046 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -45,6 +45,7 @@ static void xxmc_frame_updates(xxmc_driver_t *driver, xxmc_frame_t *frame, static void dispose_ximage (xxmc_driver_t *this, XShmSegmentInfo *shminfo, XvImage *myimage); +static const char *const prefer_types[] = VIDEO_DEVICE_XV_PREFER_TYPES; /* * Acceleration level priority. Static for now. It may well turn out that IDCT @@ -2263,11 +2264,15 @@ static XvPortID xxmc_autodetect_port(xxmc_driver_t *this, unsigned int adaptors, XvAdaptorInfo *adaptor_info, unsigned int *adaptor_num, - XvPortID base) { + XvPortID base, + xv_prefertype prefer_type) +{ unsigned int an, j; for (an = 0; an < adaptors; an++) - if (adaptor_info[an].type & XvImageMask) + if (adaptor_info[an].type & XvImageMask && + (prefer_type == xv_prefer_none || + strcasestr (adaptor_info[an].name, prefer_types[prefer_type]))) for (j = 0; j < adaptor_info[an].num_ports; j++) { XvPortID port = adaptor_info[an].base_id + j; if (port >= base && xxmc_open_port(this, port)) { @@ -2443,6 +2448,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi XvPortID xv_port; XvAdaptorInfo *adaptor_info; unsigned int adaptor_num; + xv_prefertype prefer_type; cfg_entry_t *entry; int use_more_frames; int use_unscaled; @@ -2480,19 +2486,24 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi xv_port = config->register_num (config, "video.device.xv_port", 0, VIDEO_DEVICE_XV_PORT_HELP, - 10, NULL, NULL); + 20, NULL, NULL); + prefer_type = config->register_enum (config, "video.device.xv_preferred_method", 0, + prefer_types, VIDEO_DEVICE_XV_PREFER_TYPE_HELP, + 10, NULL, NULL); if (xv_port != 0) { if (! xxmc_open_port(this, xv_port)) { xprintf(class->xine, XINE_VERBOSITY_NONE, _("%s: could not open Xv port %d - autodetecting\n"), LOG_MODULE, xv_port); - xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, xv_port); + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, xv_port, prefer_type); } else adaptor_num = xxmc_find_adaptor_by_port (xv_port, adaptors, adaptor_info); } if (!xv_port) - xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0); + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0, prefer_type); + if (!xv_port) + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0, xv_prefer_none); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, diff --git a/src/video_out/xv_common.h b/src/video_out/xv_common.h index ee2ab9a10..259afe616 100644 --- a/src/video_out/xv_common.h +++ b/src/video_out/xv_common.h @@ -56,3 +56,14 @@ #define VIDEO_DEVICE_XV_PITCH_ALIGNMENT_HELP \ _("pitch alignment workaround"), \ _("Some buggy video drivers need a workaround to function properly.") + +typedef enum { + xv_prefer_none, xv_prefer_overlay, xv_prefer_textured +} xv_prefertype; +#define VIDEO_DEVICE_XV_PREFER_TYPES \ + { "Any", "Overlay", "Textured Video", NULL } +#define VIDEO_DEVICE_XV_PREFER_TYPE_HELP \ + _("video display method preference"), \ + _("Selects which video output method is preferred. " \ + "Detection is done using the reported Xv adaptor names.\n" \ + "(Only applies when auto-detecting which Xv port to use.)") -- cgit v1.2.3 From d3572a729ae098dba38d27a2b1914b6ca17c4de1 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 10 Mar 2008 23:11:49 -0300 Subject: Fixed long delay when closing stream on dual core systems [Bug #33] --- src/xine-engine/demux.c | 15 ++++++++++----- src/xine-engine/xine.c | 3 +++ src/xine-engine/xine_internal.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index f33397256..24ee1b86d 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -198,6 +198,7 @@ void _x_demux_control_headers_done (xine_stream_t *stream) { } stream->demux_action_pending = 0; + pthread_cond_signal(&stream->demux_resume); lprintf ("headers processed.\n"); @@ -284,12 +285,14 @@ static void *demux_loop (void *stream_gen) { /* someone may want to interrupt us */ if( stream->demux_action_pending ) { - pthread_mutex_unlock( &stream->demux_lock ); + struct timeval tv; + struct timespec ts; - lprintf ("sched_yield\n"); - - sched_yield(); - pthread_mutex_lock( &stream->demux_lock ); + gettimeofday(&tv, NULL); + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = (tv.tv_usec + 100000) * 1000; + + pthread_cond_timedwait (&stream->demux_resume, &stream->demux_lock, &ts); } } @@ -365,6 +368,7 @@ int _x_demux_start_thread (xine_stream_t *stream) { stream->demux_action_pending = 1; pthread_mutex_lock( &stream->demux_lock ); stream->demux_action_pending = 0; + pthread_cond_signal(&stream->demux_resume); if( !stream->demux_thread_running ) { @@ -396,6 +400,7 @@ int _x_demux_stop_thread (xine_stream_t *stream) { pthread_mutex_lock( &stream->demux_lock ); stream->demux_thread_running = 0; stream->demux_action_pending = 0; + pthread_cond_signal(&stream->demux_resume); /* At that point, the demuxer has sent the last audio/video buffer, * so it's a safe place to flush the engine. diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 841f966d1..c207680e6 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -629,6 +629,7 @@ xine_stream_t *xine_stream_new (xine_t *this, pthread_mutex_init (&stream->meta_mutex, NULL); pthread_mutex_init (&stream->demux_lock, NULL); pthread_mutex_init (&stream->demux_mutex, NULL); + pthread_cond_init (&stream->demux_resume, NULL); pthread_mutex_init (&stream->event_queues_lock, NULL); pthread_mutex_init (&stream->counter_lock, NULL); pthread_cond_init (&stream->counter_changed, NULL); @@ -1322,6 +1323,7 @@ static int play_internal (xine_stream_t *stream, int start_pos, int start_time) pthread_mutex_lock( &stream->demux_lock ); /* demux_lock taken. now demuxer is suspended */ stream->demux_action_pending = 0; + pthread_cond_signal(&stream->demux_resume); /* set normal speed again (now that demuxer/input pair is suspended) * some input plugin may have changed speed by itself, we must ensure @@ -1448,6 +1450,7 @@ void xine_dispose_internal (xine_stream_t *stream) { pthread_mutex_destroy (&stream->current_extra_info_lock); pthread_cond_destroy (&stream->counter_changed); pthread_mutex_destroy (&stream->demux_mutex); + pthread_cond_destroy (&stream->demux_resume); pthread_mutex_destroy (&stream->demux_lock); pthread_mutex_destroy (&stream->first_frame_lock); pthread_cond_destroy (&stream->first_frame_reached); diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h index 9b69f16f1..8fb4723a5 100644 --- a/src/xine-engine/xine_internal.h +++ b/src/xine-engine/xine_internal.h @@ -333,6 +333,7 @@ struct xine_stream_s { int demux_thread_running; pthread_mutex_t demux_lock; int demux_action_pending; + pthread_cond_t demux_resume; pthread_mutex_t demux_mutex; /* used in _x_demux_... functions to synchronize order of pairwise A/V buffer operations */ extra_info_t *current_extra_info; -- cgit v1.2.3 From 0bb3f6696c0c7bd9644569bbf599d9baa43610da Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Mar 2008 01:15:58 +0000 Subject: Move ffmpeg plugin code into src/combined/ffmpeg & adapt for current ffmpeg. The source remains compilable with older ffmpeg, whether internal or external. --HG-- rename : src/libffmpeg/Makefile.am => src/combined/ffmpeg/Makefile.am rename : src/libffmpeg/ff_audio_decoder.c => src/combined/ffmpeg/ff_audio_decoder.c rename : src/libffmpeg/ff_dvaudio_decoder.c => src/combined/ffmpeg/ff_dvaudio_decoder.c rename : src/libffmpeg/ff_mpeg_parser.c => src/combined/ffmpeg/ff_mpeg_parser.c rename : src/libffmpeg/ff_mpeg_parser.h => src/combined/ffmpeg/ff_mpeg_parser.h rename : src/libffmpeg/ff_video_decoder.c => src/combined/ffmpeg/ff_video_decoder.c rename : src/libffmpeg/ffmpeg_decoder.c => src/combined/ffmpeg/ffmpeg_decoder.c rename : src/libffmpeg/ffmpeg_decoder.h => src/combined/ffmpeg/ffmpeg_decoder.h rename : src/libffmpeg/ffmpeg_encoder.c => src/combined/ffmpeg/ffmpeg_encoder.c --- src/combined/Makefile.am | 2 + src/combined/ffmpeg/Makefile.am | 47 + src/combined/ffmpeg/ff_audio_decoder.c | 551 +++++++++ src/combined/ffmpeg/ff_dvaudio_decoder.c | 432 +++++++ src/combined/ffmpeg/ff_mpeg_parser.c | 321 +++++ src/combined/ffmpeg/ff_mpeg_parser.h | 81 ++ src/combined/ffmpeg/ff_video_decoder.c | 1889 ++++++++++++++++++++++++++++++ src/combined/ffmpeg/ffmpeg_decoder.c | 326 ++++++ src/combined/ffmpeg/ffmpeg_decoder.h | 55 + src/combined/ffmpeg/ffmpeg_encoder.c | 334 ++++++ src/libffmpeg/Makefile.am | 38 +- src/libffmpeg/ff_audio_decoder.c | 551 --------- src/libffmpeg/ff_dvaudio_decoder.c | 430 ------- src/libffmpeg/ff_mpeg_parser.c | 321 ----- src/libffmpeg/ff_mpeg_parser.h | 81 -- src/libffmpeg/ff_video_decoder.c | 1889 ------------------------------ src/libffmpeg/ffmpeg_decoder.c | 326 ------ src/libffmpeg/ffmpeg_decoder.h | 53 - src/libffmpeg/ffmpeg_encoder.c | 332 ------ 19 files changed, 4039 insertions(+), 4020 deletions(-) create mode 100644 src/combined/ffmpeg/Makefile.am create mode 100644 src/combined/ffmpeg/ff_audio_decoder.c create mode 100644 src/combined/ffmpeg/ff_dvaudio_decoder.c create mode 100644 src/combined/ffmpeg/ff_mpeg_parser.c create mode 100644 src/combined/ffmpeg/ff_mpeg_parser.h create mode 100644 src/combined/ffmpeg/ff_video_decoder.c create mode 100644 src/combined/ffmpeg/ffmpeg_decoder.c create mode 100644 src/combined/ffmpeg/ffmpeg_decoder.h create mode 100644 src/combined/ffmpeg/ffmpeg_encoder.c delete mode 100644 src/libffmpeg/ff_audio_decoder.c delete mode 100644 src/libffmpeg/ff_dvaudio_decoder.c delete mode 100644 src/libffmpeg/ff_mpeg_parser.c delete mode 100644 src/libffmpeg/ff_mpeg_parser.h delete mode 100644 src/libffmpeg/ff_video_decoder.c delete mode 100644 src/libffmpeg/ffmpeg_decoder.c delete mode 100644 src/libffmpeg/ffmpeg_decoder.h delete mode 100644 src/libffmpeg/ffmpeg_encoder.c (limited to 'src') diff --git a/src/combined/Makefile.am b/src/combined/Makefile.am index 884fcf0cc..03250ef67 100644 --- a/src/combined/Makefile.am +++ b/src/combined/Makefile.am @@ -1,5 +1,7 @@ include $(top_srcdir)/misc/Makefile.common +SUBDIRS = ffmpeg + if HAVE_WAVPACK xineplug_wavpack = xineplug_wavpack.la endif diff --git a/src/combined/ffmpeg/Makefile.am b/src/combined/ffmpeg/Makefile.am new file mode 100644 index 000000000..741acdf40 --- /dev/null +++ b/src/combined/ffmpeg/Makefile.am @@ -0,0 +1,47 @@ +include $(top_srcdir)/misc/Makefile.common + +DEFAULT_INCLUDES = -I. + +if HAVE_FFMPEG +ff_cppflags = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) +link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) +else +ff_cppflags = -I$(top_srcdir)/src/libffmpeg -I$(top_srcdir)/src/libffmpeg/libavcodec -I$(top_srcdir)/src/libffmpeg/libavutil +link_ffmpeg = \ + $(top_builddir)/src/libffmpeg/libavcodec/libavcodec.la \ + $(top_builddir)/src/libffmpeg/libavutil/libavutil.la \ + $(top_builddir)/src/libffmpeg/libavcodec/libpostproc/libpostprocess.la +endif + +# ffmpeg_config.h is generated by configure +DISTCLEANFILES = ffmpeg_config.h + +# this must always be included, even if the current machine has no DXR3... +EXTRA_DIST = ffmpeg_encoder.c + +xineplug_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la + +if HAVE_DXR3 +AM_CPPFLAGS = -I$(top_srcdir)/src/dxr3 $(X_CFLAGS) $(ff_cppflags) \ + $(ZLIB_CPPFLAGS) +xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ + ffmpeg_encoder.c ff_mpeg_parser.c ffmpeg_decoder.h \ + ff_mpeg_parser.h +else +AM_CPPFLAGS = $(ff_cppflags) $(ZLIB_CPPFLAGS) +xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ + ff_mpeg_parser.c ffmpeg_decoder.h ff_mpeg_parser.h +endif + +xineplug_decode_ff_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) +xineplug_decode_ff_la_LDFLAGS = $(xineplug_ldflags) $(IMPURE_TEXT_LDFLAGS) +xineplug_decode_ff_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm $(ZLIB_LIBS) \ + $(link_ffmpeg) $(PTHREAD_LIBS) $(LTLIBINTL) + +xineplug_decode_dvaudio_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) +xineplug_decode_dvaudio_la_LDFLAGS = $(xineplug_ldflags) +xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c +xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) + +$(top_srcdir)/src/libffmpeg/libavcodec/libavcodec.la: + make -C $(top_srcdir)/src/libffmpeg diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c new file mode 100644 index 000000000..4aebd6d60 --- /dev/null +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -0,0 +1,551 @@ +/* + * Copyright (C) 2001-2005 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * xine audio decoder plugin using ffmpeg + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "../../libffmpeg/ffmpeg_config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "ffmpeg_audio_dec" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "buffer.h" +#include "xineutils.h" +#include "bswap.h" +#include "ffmpeg_decoder.h" + +#define AUDIOBUFSIZE (64 * 1024) + +typedef struct { + audio_decoder_class_t decoder_class; +} ff_audio_class_t; + +typedef struct ff_audio_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + int output_open; + int audio_channels; + int audio_bits; + int audio_sample_rate; + + unsigned char *buf; + int bufsize; + int size; + + AVCodecContext *context; + AVCodec *codec; + + char *decode_buffer; + int decoder_ok; + +} ff_audio_decoder_t; + + +static const ff_codec_t ff_audio_lookup[] = { + {BUF_AUDIO_WMAV1, CODEC_ID_WMAV1, "MS Windows Media Audio 1 (ffmpeg)"}, + {BUF_AUDIO_WMAV2, CODEC_ID_WMAV2, "MS Windows Media Audio 2 (ffmpeg)"}, + {BUF_AUDIO_14_4, CODEC_ID_RA_144, "Real 14.4 (ffmpeg)"}, + {BUF_AUDIO_28_8, CODEC_ID_RA_288, "Real 28.8 (ffmpeg)"}, + {BUF_AUDIO_MPEG, CODEC_ID_MP3, "MP3 (ffmpeg)"}, + {BUF_AUDIO_MSADPCM, CODEC_ID_ADPCM_MS, "MS ADPCM (ffmpeg)"}, + {BUF_AUDIO_QTIMAADPCM, CODEC_ID_ADPCM_IMA_QT, "QT IMA ADPCM (ffmpeg)"}, + {BUF_AUDIO_MSIMAADPCM, CODEC_ID_ADPCM_IMA_WAV, "MS IMA ADPCM (ffmpeg)"}, + {BUF_AUDIO_DK3ADPCM, CODEC_ID_ADPCM_IMA_DK3, "Duck DK3 ADPCM (ffmpeg)"}, + {BUF_AUDIO_DK4ADPCM, CODEC_ID_ADPCM_IMA_DK4, "Duck DK4 ADPCM (ffmpeg)"}, + {BUF_AUDIO_VQA_IMA, CODEC_ID_ADPCM_IMA_WS, "Westwood Studios IMA (ffmpeg)"}, + {BUF_AUDIO_SMJPEG_IMA, CODEC_ID_ADPCM_IMA_SMJPEG, "SMJPEG IMA (ffmpeg)"}, + {BUF_AUDIO_XA_ADPCM, CODEC_ID_ADPCM_XA, "CD-ROM/XA ADPCM (ffmpeg)"}, + {BUF_AUDIO_4X_ADPCM, CODEC_ID_ADPCM_4XM, "4X ADPCM (ffmpeg)"}, + {BUF_AUDIO_EA_ADPCM, CODEC_ID_ADPCM_EA, "Electronic Arts ADPCM (ffmpeg)"}, + {BUF_AUDIO_MULAW, CODEC_ID_PCM_MULAW, "mu-law logarithmic PCM (ffmpeg)"}, + {BUF_AUDIO_ALAW, CODEC_ID_PCM_ALAW, "A-law logarithmic PCM (ffmpeg)"}, + {BUF_AUDIO_ROQ, CODEC_ID_ROQ_DPCM, "RoQ DPCM (ffmpeg)"}, + {BUF_AUDIO_INTERPLAY, CODEC_ID_INTERPLAY_DPCM, "Interplay DPCM (ffmpeg)"}, + {BUF_AUDIO_MAC3, CODEC_ID_MACE3, "MACE 3:1 (ffmpeg)"}, + {BUF_AUDIO_MAC6, CODEC_ID_MACE6, "MACE 6:1 (ffmpeg)"}, + {BUF_AUDIO_XAN_DPCM, CODEC_ID_XAN_DPCM, "Origin Xan DPCM (ffmpeg)"}, + {BUF_AUDIO_VMD, CODEC_ID_VMDAUDIO, "Sierra VMD Audio (ffmpeg)"}, + {BUF_AUDIO_FLAC, CODEC_ID_FLAC, "FLAC (ffmpeg)"}, + {BUF_AUDIO_SHORTEN, CODEC_ID_SHORTEN, "Shorten (ffmpeg)"}, + {BUF_AUDIO_ALAC, CODEC_ID_ALAC, "ALAC (ffmpeg)"}, + {BUF_AUDIO_QDESIGN2, CODEC_ID_QDM2, "QDesign (ffmpeg)"}, + {BUF_AUDIO_COOK, CODEC_ID_COOK, "RealAudio Cooker (ffmpeg)"}, + {BUF_AUDIO_TRUESPEECH, CODEC_ID_TRUESPEECH, "TrueSpeech (ffmpeg)"}, + {BUF_AUDIO_TTA, CODEC_ID_TTA, "True Audio Lossless (ffmpeg)"}, + {BUF_AUDIO_SMACKER, CODEC_ID_SMACKAUDIO, "Smacker (ffmpeg)"}, + {BUF_AUDIO_FLVADPCM, CODEC_ID_ADPCM_SWF, "Flash ADPCM (ffmpeg)"}, + {BUF_AUDIO_WAVPACK, CODEC_ID_WAVPACK, "WavPack (ffmpeg)"}, +}; + + + static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) { + if (size > this->bufsize) { + this->bufsize = size + size / 2; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc( this->buf, this->bufsize ); + } +} + +static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + int bytes_consumed; + int decode_buffer_size; + int offset; + int out; + audio_buffer_t *audio_buffer; + int bytes_to_send; + + if ( (buf->decoder_flags & BUF_FLAG_HEADER) && + !(buf->decoder_flags & BUF_FLAG_SPECIAL) ) { + + /* accumulate init data */ + ff_audio_ensure_buffer_size(this, this->size + buf->size); + memcpy(this->buf + this->size, buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + size_t i; + unsigned int codec_type; + xine_waveformatex *audio_header; + + codec_type = buf->type & 0xFFFF0000; + this->codec = NULL; + + for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) + if(ff_audio_lookup[i].type == codec_type) { + pthread_mutex_lock (&ffmpeg_lock); + this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); + pthread_mutex_unlock (&ffmpeg_lock); + _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, + ff_audio_lookup[i].name); + break; + } + + if (!this->codec) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), + codec_type); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + + this->context = avcodec_alloc_context(); + + if(buf->decoder_flags & BUF_FLAG_STDHEADER) { + this->audio_sample_rate = buf->decoder_info[1]; + this->audio_channels = buf->decoder_info[3]; + + if(this->size) { + audio_header = (xine_waveformatex *)this->buf; + + this->context->block_align = audio_header->nBlockAlign; + this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; + + if(audio_header->cbSize > 0) { + this->context->extradata = xine_xmalloc(audio_header->cbSize); + this->context->extradata_size = audio_header->cbSize; + memcpy( this->context->extradata, + (uint8_t *)audio_header + sizeof(xine_waveformatex), + audio_header->cbSize ); + } + } + } else { + short *ptr; + + switch(codec_type) { + case BUF_AUDIO_14_4: + this->audio_sample_rate = 8000; + this->audio_channels = 1; + + this->context->block_align = 240; + break; + case BUF_AUDIO_28_8: + this->audio_sample_rate = _X_BE_16(&this->buf[0x30]); + this->audio_channels = this->buf[0x37]; + /* this->audio_bits = buf->content[0x35] */ + + this->context->block_align = _X_BE_16(&this->buf[0x2A]); + + this->context->extradata_size = 5*sizeof(short); + this->context->extradata = xine_xmalloc(this->context->extradata_size); + + ptr = (short *) this->context->extradata; + + ptr[0] = _X_BE_16(&this->buf[0x2C]); /* subpacket size */ + ptr[1] = _X_BE_16(&this->buf[0x28]); /* subpacket height */ + ptr[2] = _X_BE_16(&this->buf[0x16]); /* subpacket flavour */ + ptr[3] = _X_BE_32(&this->buf[0x18]); /* coded frame size */ + ptr[4] = 0; /* codec's data length */ + break; + default: + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type); + break; + } + } + + /* Current ffmpeg audio decoders always use 16 bits/sample + * buf->decoder_info[2] can't be used as it doesn't refer to the output + * bits/sample for some codecs (e.g. MS ADPCM) */ + this->audio_bits = 16; + + this->context->bits_per_sample = this->audio_bits; + this->context->sample_rate = this->audio_sample_rate; + this->context->channels = this->audio_channels; + this->context->codec_id = this->codec->id; + this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); + + this->size = 0; + + this->decode_buffer = xine_xmalloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); + + return; + } + } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && + (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) { + + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = xine_xmalloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + + } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { + + if( !this->decoder_ok ) { + if ( ! this->context || ! this->codec ) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: trying to open null codec\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + + pthread_mutex_lock (&ffmpeg_lock); + if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock (&ffmpeg_lock); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: couldn't open decoder\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } + pthread_mutex_unlock (&ffmpeg_lock); + this->decoder_ok = 1; + } + + if (!this->output_open) { + this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, + this->stream, this->audio_bits, this->audio_sample_rate, + _x_ao_channels2mode(this->audio_channels)); + } + + /* if the audio still isn't open, bail */ + if (!this->output_open) + return; + + if( buf->decoder_flags & BUF_FLAG_PREVIEW ) + return; + + ff_audio_ensure_buffer_size(this, this->size + buf->size); + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ + + offset = 0; + while (this->size>0) { + decode_buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; + bytes_consumed = avcodec_decode_audio2 (this->context, + (int16_t *)this->decode_buffer, + &decode_buffer_size, + &this->buf[offset], + this->size); + + if (bytes_consumed<0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_audio_dec: error decompressing audio frame\n"); + this->size=0; + return; + } else if (bytes_consumed == 0 && decode_buffer_size == 0) { + if (offset) + memmove(this->buf, &this->buf[offset], this->size); + return; + } + + /* dispatch the decoded audio */ + out = 0; + while (out < decode_buffer_size) { + audio_buffer = + this->stream->audio_out->get_buffer (this->stream->audio_out); + if (audio_buffer->mem_size == 0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_audio_dec: Help! Allocated audio buffer with nothing in it!\n"); + return; + } + + if ((decode_buffer_size - out) > audio_buffer->mem_size) + bytes_to_send = audio_buffer->mem_size; + else + bytes_to_send = decode_buffer_size - out; + + /* fill up this buffer */ + xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], + bytes_to_send); + /* byte count / 2 (bytes / sample) / channels */ + audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; + + audio_buffer->vpts = buf->pts; + buf->pts = 0; /* only first buffer gets the real pts */ + this->stream->audio_out->put_buffer (this->stream->audio_out, + audio_buffer, this->stream); + + out += bytes_to_send; + } + + this->size -= bytes_consumed; + offset += bytes_consumed; + } + + /* reset internal accumulation buffer */ + this->size = 0; + } + } +} + +static void ff_audio_reset (audio_decoder_t *this_gen) { + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + + this->size = 0; + + /* try to reset the wma decoder */ + if( this->context && this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); + avcodec_close (this->context); + avcodec_open (this->context, this->codec); + pthread_mutex_unlock (&ffmpeg_lock); + } +} + +static void ff_audio_discontinuity (audio_decoder_t *this_gen) { +} + +static void ff_audio_dispose (audio_decoder_t *this_gen) { + + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + + if( this->context && this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); + avcodec_close (this->context); + pthread_mutex_unlock (&ffmpeg_lock); + } + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + free(this->buf); + free(this->decode_buffer); + + if(this->context && this->context->extradata) + free(this->context->extradata); + + if(this->context) + free(this->context); + + free (this_gen); +} + +static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + ff_audio_decoder_t *this ; + + this = (ff_audio_decoder_t *) xine_xmalloc (sizeof (ff_audio_decoder_t)); + + this->audio_decoder.decode_data = ff_audio_decode_data; + this->audio_decoder.reset = ff_audio_reset; + this->audio_decoder.discontinuity = ff_audio_discontinuity; + this->audio_decoder.dispose = ff_audio_dispose; + + this->output_open = 0; + this->audio_channels = 0; + this->stream = stream; + this->buf = NULL; + this->size = 0; + this->bufsize = 0; + this->decoder_ok = 0; + + ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE); + + return &this->audio_decoder; +} + +static char *ff_audio_get_identifier (audio_decoder_class_t *this) { + return "ffmpeg audio"; +} + +static char *ff_audio_get_description (audio_decoder_class_t *this) { + return "ffmpeg based audio decoder plugin"; +} + +static void ff_audio_dispose_class (audio_decoder_class_t *this) { + free (this); +} + +void *init_audio_plugin (xine_t *xine, void *data) { + + ff_audio_class_t *this ; + + this = (ff_audio_class_t *) xine_xmalloc (sizeof (ff_audio_class_t)); + + this->decoder_class.open_plugin = ff_audio_open_plugin; + this->decoder_class.get_identifier = ff_audio_get_identifier; + this->decoder_class.get_description = ff_audio_get_description; + this->decoder_class.dispose = ff_audio_dispose_class; + + pthread_once( &once_control, init_once_routine ); + + return this; +} + +static uint32_t supported_audio_types[] = { + #ifdef CONFIG_WMAV1_DECODER + BUF_AUDIO_WMAV1, + #endif + #ifdef CONFIG_WMAV2_DECODER + BUF_AUDIO_WMAV2, + #endif + #ifdef CONFIG_RA_144_DECODER + BUF_AUDIO_14_4, + #endif + #ifdef CONFIG_RA_288_DECODER + BUF_AUDIO_28_8, + #endif + #ifdef CONFIG_MP3_DECODER + BUF_AUDIO_MPEG, + #endif + #ifdef CONFIG_ADPCM_MS_DECODER + BUF_AUDIO_MSADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_QT_DECODER + BUF_AUDIO_QTIMAADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_WAV_DECODER + BUF_AUDIO_MSIMAADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_DK3_DECODER + BUF_AUDIO_DK3ADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_DK4_DECODER + BUF_AUDIO_DK4ADPCM, + #endif + #ifdef CONFIG_ADPCM_IMA_WS_DECODER + BUF_AUDIO_VQA_IMA, + #endif + #ifdef CONFIG_ADPCM_IMA_SMJPEG_DECODER + BUF_AUDIO_SMJPEG_IMA, + #endif + #ifdef CONFIG_ADPCM_XA_DECODER + BUF_AUDIO_XA_ADPCM, + #endif + #ifdef CONFIG_ADPCM_4XM_DECODER + BUF_AUDIO_4X_ADPCM, + #endif + #ifdef CONFIG_ADPCM_EA_DECODER + BUF_AUDIO_EA_ADPCM, + #endif + #ifdef CONFIG_PCM_MULAW_DECODER + BUF_AUDIO_MULAW, + #endif + #ifdef CONFIG_PCM_ALAW_DECODER + BUF_AUDIO_ALAW, + #endif + #ifdef CONFIG_ROQ_DPCM_DECODER + BUF_AUDIO_ROQ, + #endif + #ifdef CONFIG_INTERPLAY_DPCM_DECODER + BUF_AUDIO_INTERPLAY, + #endif + #ifdef CONFIG_MACE3_DECODER + BUF_AUDIO_MAC3, + #endif + #ifdef CONFIG_MACE6_DECODER + BUF_AUDIO_MAC6, + #endif + #ifdef CONFIG_XAN_DPCM_DECODER + BUF_AUDIO_XAN_DPCM, + #endif + #ifdef CONFIG_VMDAUDIO_DECODER + BUF_AUDIO_VMD, + #endif + #ifdef CONFIG_FLAC_DECODER + BUF_AUDIO_FLAC, + #endif + #ifdef CONFIG_SHORTEN_DECODER + BUF_AUDIO_SHORTEN, + #endif + #ifdef CONFIG_ALAC_DECODER + BUF_AUDIO_ALAC, + #endif + #ifdef CONFIG_QDM2_DECODER + BUF_AUDIO_QDESIGN2, + #endif + #ifdef CONFIG_COOK_DECODER + BUF_AUDIO_COOK, + #endif + #ifdef CONFIG_TRUESPEECH_DECODER + BUF_AUDIO_TRUESPEECH, + #endif + #ifdef CONFIG_TTA_DECODER + BUF_AUDIO_TTA, + #endif + #ifdef CONFIG_SMACKAUDIO_DECODER + BUF_AUDIO_SMACKER, + #endif + #ifdef CONFIG_ADPCM_SWF_DECODER + BUF_AUDIO_FLVADPCM, + #endif + #ifdef CONFIG_WAVPACK_DECODER + BUF_AUDIO_WAVPACK, + #endif + + 0 +}; + +decoder_info_t dec_info_ffmpeg_audio = { + supported_audio_types, /* supported types */ + 6 /* priority */ +}; diff --git a/src/combined/ffmpeg/ff_dvaudio_decoder.c b/src/combined/ffmpeg/ff_dvaudio_decoder.c new file mode 100644 index 000000000..4704c1a2a --- /dev/null +++ b/src/combined/ffmpeg/ff_dvaudio_decoder.c @@ -0,0 +1,432 @@ +/* + * Copyright (C) 2005 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * dv audio decoder based on patch by Dan Dennedy + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#define LOG_MODULE "dvaudio" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include "xine_internal.h" +#include "buffer.h" +#include "xineutils.h" + +#ifdef _MSC_VER +/* ffmpeg has own definitions of those types */ +# undef int8_t +# undef uint8_t +# undef int16_t +# undef uint16_t +# undef int32_t +# undef uint32_t +# undef int64_t +# undef uint64_t +#endif + +#ifdef HAVE_FFMPEG_AVUTIL_H +# include +#elif defined HAVE_FFMPEG +# include +#else +# include "../../libffmpeg/libavcodec/avcodec.h" +#endif + +#include "../../libffmpeg/libavcodec/dvdata.h" + +#ifdef _MSC_VER +# undef malloc +# undef free +# undef realloc +#endif + +#define AUDIOBUFSIZE 128*1024 +#define MAXFRAMESIZE 131072 + + +typedef struct { + audio_decoder_class_t decoder_class; +} dvaudio_class_t; + +typedef struct dvaudio_decoder_s { + audio_decoder_t audio_decoder; + + xine_stream_t *stream; + + int output_open; + int audio_channels; + int audio_bits; + int audio_sample_rate; + + unsigned char *buf; + int bufsize; + int size; + + char *decode_buffer; + int decoder_ok; + +} dvaudio_decoder_t; + + +/* + * This is the dumbest implementation of all -- it simply looks at + * a fixed offset and if pack isn't there -- fails. We might want + * to have a fallback mechanism for complete search of missing packs. + */ +static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) +{ + int offs; + + switch (t) { + case dv_audio_source: + offs = (80*6 + 80*16*3 + 3); + break; + case dv_audio_control: + offs = (80*6 + 80*16*4 + 3); + break; + case dv_video_control: + offs = (80*5 + 48 + 5); + break; + default: + return NULL; + } + + return (frame[offs] == t ? &frame[offs] : NULL); +} + +static inline uint16_t dv_audio_12to16(uint16_t sample) +{ + uint16_t shift, result; + + sample = (sample < 0x800) ? sample : sample | 0xf000; + shift = (sample & 0xf00) >> 8; + + if (shift < 0x2 || shift > 0xd) { + result = sample; + } else if (shift < 0x8) { + shift--; + result = (sample - (256 * shift)) << shift; + } else { + shift = 0xe - shift; + result = ((sample + ((256 * shift) + 1)) << shift) - 1; + } + + return result; +} + +/* + * There's a couple of assumptions being made here: + * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. + * We can pass them upwards when ffmpeg will be ready to deal with them. + * 2. We don't do software emphasis. + * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples + * are converted into 16bit linear ones. + */ +static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2) +{ + int size, i, j, d, of, smpls, freq, quant, half_ch; + uint16_t lc, rc; + const DVprofile* sys; + const uint8_t* as_pack; + + as_pack = dv_extract_pack(frame, dv_audio_source); + if (!as_pack) /* No audio ? */ + return 0; + + sys = dv_frame_profile(frame); + smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ + freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ + quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ + + if (quant > 1) + return -1; /* Unsupported quantization */ + + size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ + half_ch = sys->difseg_size/2; + + /* for each DIF segment */ + for (i = 0; i < sys->difseg_size; i++) { + frame += 6 * 80; /* skip DIF segment header */ + if (quant == 1 && i == half_ch) { + if (!pcm2) + break; + else + pcm = pcm2; + } + + for (j = 0; j < 9; j++) { + for (d = 8; d < 80; d += 2) { + if (quant == 0) { /* 16bit quantization */ + of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; + if (of*2 >= size) + continue; + +#ifdef WORDS_BIGENDIAN + pcm[of*2] = frame[d]; + pcm[of*2+1] = frame[d+1]; +#else + pcm[of*2] = frame[d+1]; + pcm[of*2+1] = frame[d]; +#endif + if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) + pcm[of*2+1] = 0; + } else { /* 12bit quantization */ + lc = ((uint16_t)frame[d] << 4) | + ((uint16_t)frame[d+2] >> 4); + rc = ((uint16_t)frame[d+1] << 4) | + ((uint16_t)frame[d+2] & 0x0f); + lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); + rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); + + of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; + if (of*2 >= size) + continue; + +#ifdef WORDS_BIGENDIAN + pcm[of*2] = lc >> 8; + pcm[of*2+1] = lc & 0xff; +#else + pcm[of*2] = lc & 0xff; + pcm[of*2+1] = lc >> 8; +#endif + of = sys->audio_shuffle[i%half_ch+half_ch][j] + + (d - 8)/3 * sys->audio_stride; +#ifdef WORDS_BIGENDIAN + pcm[of*2] = rc >> 8; + pcm[of*2+1] = rc & 0xff; +#else + pcm[of*2] = rc & 0xff; + pcm[of*2+1] = rc >> 8; +#endif + ++d; + } + } + + frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ + } + } + + return size; +} + +static void dvaudio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { + + dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; + int bytes_consumed; + int decode_buffer_size; + int offset; + int out; + audio_buffer_t *audio_buffer; + int bytes_to_send; + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + if (buf->decoder_flags & BUF_FLAG_STDHEADER) { + this->buf = xine_xmalloc(AUDIOBUFSIZE); + this->bufsize = AUDIOBUFSIZE; + this->size = 0; + this->decode_buffer = xine_xmalloc(MAXFRAMESIZE); + + this->audio_sample_rate = buf->decoder_info[1]; + this->audio_bits = buf->decoder_info[2]; + this->audio_channels = buf->decoder_info[3]; + + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DV Audio"); + + this->decoder_ok = 1; + + return; + } + + if (this->decoder_ok && !(buf->decoder_flags & (BUF_FLAG_HEADER|BUF_FLAG_SPECIAL))) { + + if (!this->output_open) { + this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, + this->stream, this->audio_bits, this->audio_sample_rate, + _x_ao_channels2mode(this->audio_channels)); + } + + /* if the audio still isn't open, bail */ + if (!this->output_open) + return; + + if( this->size + buf->size > this->bufsize ) { + this->bufsize = this->size + 2 * buf->size; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("dvaudio: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc( this->buf, this->bufsize ); + } + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ + + offset = 0; + while (this->size>0) { + decode_buffer_size = dv_extract_audio(&this->buf[offset], this->decode_buffer, NULL); + + if (decode_buffer_size > -1) + bytes_consumed = dv_frame_profile(&this->buf[offset])->frame_size; + else + bytes_consumed = decode_buffer_size; + + /* dispatch the decoded audio */ + out = 0; + while (out < decode_buffer_size) { + audio_buffer = + this->stream->audio_out->get_buffer (this->stream->audio_out); + if (audio_buffer->mem_size == 0) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "dvaudio: Help! Allocated audio buffer with nothing in it!\n"); + return; + } + + if ((decode_buffer_size - out) > audio_buffer->mem_size) + bytes_to_send = audio_buffer->mem_size; + else + bytes_to_send = decode_buffer_size - out; + + /* fill up this buffer */ + xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], + bytes_to_send); + /* byte count / 2 (bytes / sample) / channels */ + audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; + + audio_buffer->vpts = buf->pts; + buf->pts = 0; /* only first buffer gets the real pts */ + this->stream->audio_out->put_buffer (this->stream->audio_out, + audio_buffer, this->stream); + + out += bytes_to_send; + } + + this->size -= bytes_consumed; + offset += bytes_consumed; + } + + /* reset internal accumulation buffer */ + this->size = 0; + } + } +} + +static void dvaudio_reset (audio_decoder_t *this_gen) { + dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; + + this->size = 0; +} + +static void dvaudio_discontinuity (audio_decoder_t *this_gen) { +} + +static void dvaudio_dispose (audio_decoder_t *this_gen) { + + dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; + + if (this->output_open) + this->stream->audio_out->close (this->stream->audio_out, this->stream); + this->output_open = 0; + + free(this->buf); + free(this->decode_buffer); + + free (this_gen); +} + +static audio_decoder_t *dvaudio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { + + dvaudio_decoder_t *this ; + + this = (dvaudio_decoder_t *) xine_xmalloc (sizeof (dvaudio_decoder_t)); + + this->audio_decoder.decode_data = dvaudio_decode_data; + this->audio_decoder.reset = dvaudio_reset; + this->audio_decoder.discontinuity = dvaudio_discontinuity; + this->audio_decoder.dispose = dvaudio_dispose; + + this->output_open = 0; + this->audio_channels = 0; + this->stream = stream; + this->buf = NULL; + this->size = 0; + this->decoder_ok = 0; + + return &this->audio_decoder; +} + +static char *dvaudio_get_identifier (audio_decoder_class_t *this) { + return "dv audio"; +} + +static char *dvaudio_get_description (audio_decoder_class_t *this) { + return "dv audio decoder plugin"; +} + +static void dvaudio_dispose_class (audio_decoder_class_t *this) { + free (this); +} + +static void *init_dvaudio_plugin (xine_t *xine, void *data) { + + dvaudio_class_t *this ; + + this = (dvaudio_class_t *) xine_xmalloc (sizeof (dvaudio_class_t)); + + this->decoder_class.open_plugin = dvaudio_open_plugin; + this->decoder_class.get_identifier = dvaudio_get_identifier; + this->decoder_class.get_description = dvaudio_get_description; + this->decoder_class.dispose = dvaudio_dispose_class; + + return this; +} + +static uint32_t supported_audio_types[] = { + BUF_AUDIO_DV, + 0 +}; + +static const decoder_info_t dec_info_dvaudio = { + supported_audio_types, /* supported types */ + 5 /* priority */ +}; + +/* + * exported plugin catalog entry + */ + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_AUDIO_DECODER, 15, "dvaudio", XINE_VERSION_CODE, &dec_info_dvaudio, init_dvaudio_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/combined/ffmpeg/ff_mpeg_parser.c b/src/combined/ffmpeg/ff_mpeg_parser.c new file mode 100644 index 000000000..70901d93b --- /dev/null +++ b/src/combined/ffmpeg/ff_mpeg_parser.c @@ -0,0 +1,321 @@ +/* + * Copyright (C) 2001-2004 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) + * based on libmpeg2 decoder. + */ +#define LOG_MODULE "mpeg_parser" +#define LOG_VERBOSE +/* +#define LOG +*/ +#include "ff_mpeg_parser.h" + +/* mpeg frame rate table from lavc */ +static const int frame_rate_tab[][2] = { + { 0, 0}, + {24000, 1001}, + { 24, 1}, + { 25, 1}, + {30000, 1001}, + { 30, 1}, + { 50, 1}, + {60000, 1001}, + { 60, 1}, + /* Xing's 15fps: (9) */ + { 15, 1}, + /* libmpeg3's "Unofficial economy rates": (10-13) */ + { 5, 1}, + { 10, 1}, + { 12, 1}, + { 15, 1}, + { 0, 0}, +}; + +void mpeg_parser_init (mpeg_parser_t *parser) +{ + parser->chunk_buffer = xine_xmalloc(BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); + mpeg_parser_reset(parser); +} + +void mpeg_parser_dispose (mpeg_parser_t *parser) +{ + if ( parser == NULL ) return; + + free(parser->chunk_buffer); +} + +void mpeg_parser_reset (mpeg_parser_t *parser) +{ + parser->shift = 0xffffff00; + parser->is_sequence_needed = 1; + parser->in_slice = 0; + parser->chunk_ptr = parser->chunk_buffer; + parser->chunk_start = parser->chunk_buffer; + parser->buffer_size = 0; + parser->code = 0xb4; + parser->picture_coding_type = 0; + parser->width = 0; + parser->height = 0; + parser->rate_code = 0; + parser->aspect_ratio_info = 0; + parser->frame_duration = 0; + parser->is_mpeg1 = 0; + parser->has_sequence = 0; + parser->frame_aspect_ratio = 0.0; +} + +static void parse_header_picture (mpeg_parser_t *parser, uint8_t * buffer) +{ + parser->picture_coding_type = (buffer [1] >> 3) & 7; +} + +static double get_aspect_ratio(mpeg_parser_t *parser) +{ + double ratio; + double mpeg1_pel_ratio[16] = {1.0 /* forbidden */, + 1.0, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, + 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 1.0 /*reserved*/ }; + + if( !parser->is_mpeg1 ) { + /* these hardcoded values are defined on mpeg2 standard for + * aspect ratio. other values are reserved or forbidden. */ + switch (parser->aspect_ratio_info) { + case 2: + ratio = 4.0 / 3.0; + break; + case 3: + ratio = 16.0 / 9.0; + break; + case 4: + ratio = 2.11 / 1.0; + break; + case 1: + default: + ratio = (double)parser->width / (double)parser->height; + break; + } + } else { + /* mpeg1 constants refer to pixel aspect ratio */ + ratio = (double)parser->width / (double)parser->height; + ratio /= mpeg1_pel_ratio[parser->aspect_ratio_info]; + } + + return ratio; +} + +static int parse_chunk (mpeg_parser_t *parser, int code, uint8_t *buffer, int len) +{ + int is_frame_done; + int next_code = parser->code; + + /* wait for sequence_header_code */ + if (parser->is_sequence_needed) { + if (code != 0xb3) { + lprintf("waiting for sequence header\n"); + parser->chunk_ptr = parser->chunk_buffer; + return 0; + } + } + + is_frame_done = parser->in_slice && ((!next_code) || (next_code == 0xb7)); + + if (is_frame_done) + parser->in_slice = 0; + + switch (code) { + case 0x00: /* picture_start_code */ + + parse_header_picture (parser, buffer); + + parser->in_slice = 1; + + switch (parser->picture_coding_type) { + case B_TYPE: + lprintf ("B-Frame\n"); + break; + + case P_TYPE: + lprintf ("P-Frame\n"); + break; + + case I_TYPE: + lprintf ("I-Frame\n"); + break; + } + break; + + case 0xb2: /* user data code */ + /* process_userdata(mpeg2dec, buffer); */ + break; + + case 0xb3: /* sequence_header_code */ + { + int value; + uint16_t width, height; + + if (parser->is_sequence_needed) { + parser->is_sequence_needed = 0; + } + + if ((buffer[6] & 0x20) != 0x20) { + lprintf("Invalid sequence: missing marker_bit\n"); + parser->has_sequence = 0; + break; /* missing marker_bit */ + } + + value = (buffer[0] << 16) | + (buffer[1] << 8) | + buffer[2]; + width = ((value >> 12) + 15) & ~15; + height = ((value & 0xfff) + 15) & ~15; + + if ((width > 1920) || (height > 1152)) { + lprintf("Invalid sequence: width=%d, height=%d\n", width, height); + parser->has_sequence = 0; + break; /* size restrictions for MP@HL */ + } + + parser->width = width; + parser->height = height; + parser->rate_code = buffer[3] & 15; + parser->aspect_ratio_info = buffer[3] >> 4; + + if (parser->rate_code < (sizeof(frame_rate_tab)/sizeof(*frame_rate_tab))) { + parser->frame_duration = 90000; + parser->frame_duration *= frame_rate_tab[parser->rate_code][1]; + parser->frame_duration /= frame_rate_tab[parser->rate_code][0]; + } else { + printf ("invalid/unknown frame rate code : %d \n", + parser->rate_code); + parser->frame_duration = 0; + } + + parser->has_sequence = 1; + parser->is_mpeg1 = 1; + } + break; + + case 0xb5: /* extension_start_code */ + switch (buffer[0] & 0xf0) { + case 0x10: /* sequence extension */ + parser->is_mpeg1 = 0; + } + + default: + if (code >= 0xb9) + lprintf ("stream not demultiplexed ?\n"); + + if (code >= 0xb0) + break; + } + return is_frame_done; +} + +static inline uint8_t *copy_chunk (mpeg_parser_t *parser, + uint8_t *current, uint8_t *end) +{ + uint32_t shift; + uint8_t *chunk_ptr; + uint8_t *limit; + uint8_t byte; + + shift = parser->shift; + chunk_ptr = parser->chunk_ptr; + + limit = current + (parser->chunk_buffer + BUFFER_SIZE - chunk_ptr); + if (limit > end) + limit = end; + + while (1) { + + byte = *current++; + *chunk_ptr++ = byte; + if (shift != 0x00000100) { + shift = (shift | byte) << 8; + if (current < limit) + continue; + if (current == end) { + parser->chunk_ptr = chunk_ptr; + parser->shift = shift; + lprintf("Need more bytes\n"); + return NULL; + } else { + /* we filled the chunk buffer without finding a start code */ + lprintf("Buffer full\n"); + parser->code = 0xb4; /* sequence_error_code */ + parser->chunk_ptr = parser->chunk_buffer; + return current; + } + } + lprintf("New chunk: 0x%2X\n", byte); + parser->chunk_ptr = chunk_ptr; + parser->shift = 0xffffff00; + parser->code = byte; + return current; + } +} + + +uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, + uint8_t *current, uint8_t *end, + int *flush) +{ + int ret; + uint8_t code; + + ret = 0; + *flush = 0; + + while (current != end) { + if (parser->chunk_ptr == parser->chunk_buffer) { + /* write the beginning of the chunk */ + parser->chunk_buffer[0] = 0x00; + parser->chunk_buffer[1] = 0x00; + parser->chunk_buffer[2] = 0x01; + parser->chunk_buffer[3] = parser->code; + parser->chunk_ptr += 4; + parser->chunk_start = parser->chunk_ptr; + parser->has_sequence = 0; + } + + code = parser->code; + + current = copy_chunk (parser, current, end); + if (current == NULL) + return NULL; + ret = parse_chunk (parser, code, parser->chunk_start, + parser->chunk_ptr - parser->chunk_start - 4); + parser->chunk_start = parser->chunk_ptr; + if (ret == 1) { + if (parser->has_sequence) { + parser->frame_aspect_ratio = get_aspect_ratio(parser); + } + parser->buffer_size = parser->chunk_ptr - parser->chunk_buffer - 4; + parser->chunk_ptr = parser->chunk_buffer; + + if (parser->code == 0xb7) /* sequence end, maybe a still menu */ + *flush = 1; + + return current; + } + } + + return NULL; +} diff --git a/src/combined/ffmpeg/ff_mpeg_parser.h b/src/combined/ffmpeg/ff_mpeg_parser.h new file mode 100644 index 000000000..ea43a6ce4 --- /dev/null +++ b/src/combined/ffmpeg/ff_mpeg_parser.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2001-2004 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) + * based on libmpeg2 decoder. + */ +#ifndef HAVE_MPEG_PARSER_H +#define HAVE_MPEG_PARSER_H + +#include "xine_internal.h" +#include "ffmpeg_decoder.h" + +#define BUFFER_SIZE (1194 * 1024) /* libmpeg2's buffer size */ + +/* picture coding type (mpeg2 header) */ +#define I_TYPE 1 +#define P_TYPE 2 +#define B_TYPE 3 +#define D_TYPE 4 + +typedef struct mpeg_parser_s { + uint8_t *chunk_buffer; + uint8_t *chunk_ptr; + uint8_t *chunk_start; + uint32_t shift; + int buffer_size; + uint8_t code; + uint8_t picture_coding_type; + + uint8_t is_sequence_needed:1; + uint8_t is_mpeg1:1; /* public */ + uint8_t has_sequence:1; /* public */ + uint8_t in_slice:1; + + uint8_t rate_code:4; + + int aspect_ratio_info; + + /* public properties */ + uint16_t width; + uint16_t height; + int frame_duration; + double frame_aspect_ratio; + +} mpeg_parser_t; + +/* parser initialization */ +void mpeg_parser_init (mpeg_parser_t *parser); + +/* parser disposal */ +void mpeg_parser_dispose (mpeg_parser_t *parser); + +/* read a frame + * return a pointer to the first byte of the next frame + * or NULL if more bytes are needed + * *flush is set to 1 if the decoder must be flushed (needed for still menus) + */ +uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, + uint8_t *current, uint8_t *end, + int *flush); + +/* reset the parser */ +void mpeg_parser_reset (mpeg_parser_t *parser); + +#endif /* HAVE_MPEG_PARSER_H */ diff --git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c new file mode 100644 index 000000000..4e772dbca --- /dev/null +++ b/src/combined/ffmpeg/ff_video_decoder.c @@ -0,0 +1,1889 @@ +/* + * Copyright (C) 2001-2007 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * xine video decoder plugin using ffmpeg + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "../../libffmpeg/ffmpeg_config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "ffmpeg_video_dec" +#define LOG_VERBOSE +/* +#define LOG +*/ +#include "xine_internal.h" +#include "bswap.h" +#include "buffer.h" +#include "xineutils.h" +#include "ffmpeg_decoder.h" +#include "ff_mpeg_parser.h" + +#ifdef HAVE_FFMPEG_AVUTIL_H +# include +#else +# include +#endif + +#define VIDEOBUFSIZE (128*1024) +#define SLICE_BUFFER_SIZE (1194*1024) + +#define SLICE_OFFSET_SIZE 128 + +#define ENABLE_DIRECT_RENDERING + +typedef struct ff_video_decoder_s ff_video_decoder_t; + +typedef struct ff_video_class_s { + video_decoder_class_t decoder_class; + + int pp_quality; + int thread_count; + int8_t skip_loop_filter_enum; + int8_t choose_speed_over_accuracy; + + xine_t *xine; +} ff_video_class_t; + +struct ff_video_decoder_s { + video_decoder_t video_decoder; + + ff_video_class_t *class; + + xine_stream_t *stream; + int64_t pts; + int video_step; + + uint8_t decoder_ok:1; + uint8_t decoder_init_mode:1; + uint8_t is_mpeg12:1; + uint8_t pp_available:1; + uint8_t yuv_init:1; + uint8_t is_direct_rendering_disabled:1; + uint8_t cs_convert_init:1; + uint8_t assume_bad_field_picture:1; + + xine_bmiheader bih; + unsigned char *buf; + int bufsize; + int size; + int skipframes; + + int slice_offset_size; + + AVFrame *av_frame; + AVCodecContext *context; + AVCodec *codec; + + int pp_quality; + int pp_flags; + pp_context_t *pp_context; + pp_mode_t *pp_mode; + + /* mpeg-es parsing */ + mpeg_parser_t *mpeg_parser; + + double aspect_ratio; + int aspect_ratio_prio; + int frame_flags; + int crop_right, crop_bottom; + + int output_format; + + xine_list_t *dr1_frames; + + yuv_planes_t yuv; + + AVPaletteControl palette_control; +}; + + +static void set_stream_info(ff_video_decoder_t *this) { + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->bih.biWidth); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->bih.biHeight); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, this->aspect_ratio * 10000); +} + +#ifdef ENABLE_DIRECT_RENDERING +/* called from ffmpeg to do direct rendering method 1 */ +static int get_buffer(AVCodecContext *context, AVFrame *av_frame){ + ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; + vo_frame_t *img; + int width = context->width; + int height = context->height; + + if (!this->bih.biWidth || !this->bih.biHeight) { + this->bih.biWidth = width; + this->bih.biHeight = height; + + if (this->aspect_ratio_prio == 0) { + this->aspect_ratio = (double)width / (double)height; + this->aspect_ratio_prio = 1; + lprintf("default aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + } + + avcodec_align_dimensions(context, &width, &height); + + if( this->context->pix_fmt != PIX_FMT_YUV420P ) { + if (!this->is_direct_rendering_disabled) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n")); + this->is_direct_rendering_disabled = 1; + } + + /* FIXME: why should i have to do that ? */ + av_frame->data[0]= NULL; + av_frame->data[1]= NULL; + av_frame->data[2]= NULL; + return avcodec_default_get_buffer(context, av_frame); + } + + if((width != this->bih.biWidth) || (height != this->bih.biHeight)) { + if(this->stream->video_out->get_capabilities(this->stream->video_out) & VO_CAP_CROP) { + this->crop_right = width - this->bih.biWidth; + this->crop_bottom = height - this->bih.biHeight; + } else { + if (!this->is_direct_rendering_disabled) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n")); + this->is_direct_rendering_disabled = 1; + } + /* FIXME: why should i have to do that ? */ + av_frame->data[0]= NULL; + av_frame->data[1]= NULL; + av_frame->data[2]= NULL; + return avcodec_default_get_buffer(context, av_frame); + } + } + + img = this->stream->video_out->get_frame (this->stream->video_out, + width, + height, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + + av_frame->opaque = img; + + av_frame->data[0]= img->base[0]; + av_frame->data[1]= img->base[1]; + av_frame->data[2]= img->base[2]; + + av_frame->linesize[0] = img->pitches[0]; + av_frame->linesize[1] = img->pitches[1]; + av_frame->linesize[2] = img->pitches[2]; + + /* We should really keep track of the ages of xine frames (see + * avcodec_default_get_buffer in libavcodec/utils.c) + * For the moment tell ffmpeg that every frame is new (age = bignumber) */ + av_frame->age = 256*256*256*64; + + av_frame->type= FF_BUFFER_TYPE_USER; + + xine_list_push_back(this->dr1_frames, av_frame); + + return 0; +} + +static void release_buffer(struct AVCodecContext *context, AVFrame *av_frame){ + ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; + + if (av_frame->type == FF_BUFFER_TYPE_USER) { + if ( av_frame->opaque ) { + vo_frame_t *img = (vo_frame_t *)av_frame->opaque; + + img->free(img); + } + + xine_list_iterator_t it; + + it = xine_list_find(this->dr1_frames, av_frame); + assert(it); + if( it != NULL ) + xine_list_remove(this->dr1_frames, it); + } else { + avcodec_default_release_buffer(context, av_frame); + } + + av_frame->opaque = NULL; + av_frame->data[0]= NULL; + av_frame->data[1]= NULL; + av_frame->data[2]= NULL; +} +#endif + +static const ff_codec_t ff_video_lookup[] = { + {BUF_VIDEO_MSMPEG4_V1, CODEC_ID_MSMPEG4V1, "Microsoft MPEG-4 v1 (ffmpeg)"}, + {BUF_VIDEO_MSMPEG4_V2, CODEC_ID_MSMPEG4V2, "Microsoft MPEG-4 v2 (ffmpeg)"}, + {BUF_VIDEO_MSMPEG4_V3, CODEC_ID_MSMPEG4V3, "Microsoft MPEG-4 v3 (ffmpeg)"}, + {BUF_VIDEO_WMV7, CODEC_ID_WMV1, "MS Windows Media Video 7 (ffmpeg)"}, + {BUF_VIDEO_WMV8, CODEC_ID_WMV2, "MS Windows Media Video 8 (ffmpeg)"}, + {BUF_VIDEO_WMV9, CODEC_ID_WMV3, "MS Windows Media Video 9 (ffmpeg)"}, + {BUF_VIDEO_VC1, CODEC_ID_VC1, "MS Windows Media Video VC-1 (ffmpeg)"}, + {BUF_VIDEO_MPEG4, CODEC_ID_MPEG4, "ISO MPEG-4 (ffmpeg)"}, + {BUF_VIDEO_XVID, CODEC_ID_MPEG4, "ISO MPEG-4 (XviD, ffmpeg)"}, + {BUF_VIDEO_DIVX5, CODEC_ID_MPEG4, "ISO MPEG-4 (DivX5, ffmpeg)"}, + {BUF_VIDEO_3IVX, CODEC_ID_MPEG4, "ISO MPEG-4 (3ivx, ffmpeg)"}, + {BUF_VIDEO_JPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, + {BUF_VIDEO_MJPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, + {BUF_VIDEO_MJPEG_B, CODEC_ID_MJPEGB, "Motion JPEG B (ffmpeg)"}, + {BUF_VIDEO_I263, CODEC_ID_H263I, "ITU H.263 (ffmpeg)"}, + {BUF_VIDEO_H263, CODEC_ID_H263, "H.263 (ffmpeg)"}, + {BUF_VIDEO_RV10, CODEC_ID_RV10, "Real Video 1.0 (ffmpeg)"}, + {BUF_VIDEO_RV20, CODEC_ID_RV20, "Real Video 2.0 (ffmpeg)"}, + {BUF_VIDEO_IV31, CODEC_ID_INDEO3, "Indeo Video 3.1 (ffmpeg)"}, + {BUF_VIDEO_IV32, CODEC_ID_INDEO3, "Indeo Video 3.2 (ffmpeg)"}, + {BUF_VIDEO_SORENSON_V1, CODEC_ID_SVQ1, "Sorenson Video 1 (ffmpeg)"}, + {BUF_VIDEO_SORENSON_V3, CODEC_ID_SVQ3, "Sorenson Video 3 (ffmpeg)"}, + {BUF_VIDEO_DV, CODEC_ID_DVVIDEO, "DV (ffmpeg)"}, + {BUF_VIDEO_HUFFYUV, CODEC_ID_HUFFYUV, "HuffYUV (ffmpeg)"}, + {BUF_VIDEO_VP31, CODEC_ID_VP3, "On2 VP3.1 (ffmpeg)"}, + {BUF_VIDEO_VP5, CODEC_ID_VP5, "On2 VP5 (ffmpeg)"}, + {BUF_VIDEO_VP6, CODEC_ID_VP6, "On2 VP6 (ffmpeg)"}, + {BUF_VIDEO_VP6F, CODEC_ID_VP6F, "On2 VP6 (ffmpeg)"}, + {BUF_VIDEO_4XM, CODEC_ID_4XM, "4X Video (ffmpeg)"}, + {BUF_VIDEO_CINEPAK, CODEC_ID_CINEPAK, "Cinepak (ffmpeg)"}, + {BUF_VIDEO_MSVC, CODEC_ID_MSVIDEO1, "Microsoft Video 1 (ffmpeg)"}, + {BUF_VIDEO_MSRLE, CODEC_ID_MSRLE, "Microsoft RLE (ffmpeg)"}, + {BUF_VIDEO_RPZA, CODEC_ID_RPZA, "Apple Quicktime Video/RPZA (ffmpeg)"}, + {BUF_VIDEO_CYUV, CODEC_ID_CYUV, "Creative YUV (ffmpeg)"}, + {BUF_VIDEO_ROQ, CODEC_ID_ROQ, "Id Software RoQ (ffmpeg)"}, + {BUF_VIDEO_IDCIN, CODEC_ID_IDCIN, "Id Software CIN (ffmpeg)"}, + {BUF_VIDEO_WC3, CODEC_ID_XAN_WC3, "Xan (ffmpeg)"}, + {BUF_VIDEO_VQA, CODEC_ID_WS_VQA, "Westwood Studios VQA (ffmpeg)"}, + {BUF_VIDEO_INTERPLAY, CODEC_ID_INTERPLAY_VIDEO, "Interplay MVE (ffmpeg)"}, + {BUF_VIDEO_FLI, CODEC_ID_FLIC, "FLIC Video (ffmpeg)"}, + {BUF_VIDEO_8BPS, CODEC_ID_8BPS, "Planar RGB (ffmpeg)"}, + {BUF_VIDEO_SMC, CODEC_ID_SMC, "Apple Quicktime Graphics/SMC (ffmpeg)"}, + {BUF_VIDEO_DUCKTM1, CODEC_ID_TRUEMOTION1,"Duck TrueMotion v1 (ffmpeg)"}, + {BUF_VIDEO_DUCKTM2, CODEC_ID_TRUEMOTION2,"Duck TrueMotion v2 (ffmpeg)"}, + {BUF_VIDEO_VMD, CODEC_ID_VMDVIDEO, "Sierra VMD Video (ffmpeg)"}, + {BUF_VIDEO_ZLIB, CODEC_ID_ZLIB, "ZLIB Video (ffmpeg)"}, + {BUF_VIDEO_MSZH, CODEC_ID_MSZH, "MSZH Video (ffmpeg)"}, + {BUF_VIDEO_ASV1, CODEC_ID_ASV1, "ASV v1 Video (ffmpeg)"}, + {BUF_VIDEO_ASV2, CODEC_ID_ASV2, "ASV v2 Video (ffmpeg)"}, + {BUF_VIDEO_ATIVCR1, CODEC_ID_VCR1, "ATI VCR-1 (ffmpeg)"}, + {BUF_VIDEO_FLV1, CODEC_ID_FLV1, "Flash Video (ffmpeg)"}, + {BUF_VIDEO_QTRLE, CODEC_ID_QTRLE, "Apple Quicktime Animation/RLE (ffmpeg)"}, + {BUF_VIDEO_H264, CODEC_ID_H264, "H.264/AVC (ffmpeg)"}, + {BUF_VIDEO_H261, CODEC_ID_H261, "H.261 (ffmpeg)"}, + {BUF_VIDEO_AASC, CODEC_ID_AASC, "Autodesk Video (ffmpeg)"}, + {BUF_VIDEO_LOCO, CODEC_ID_LOCO, "LOCO (ffmpeg)"}, + {BUF_VIDEO_QDRW, CODEC_ID_QDRAW, "QuickDraw (ffmpeg)"}, + {BUF_VIDEO_QPEG, CODEC_ID_QPEG, "Q-Team QPEG (ffmpeg)"}, + {BUF_VIDEO_TSCC, CODEC_ID_TSCC, "TechSmith Video (ffmpeg)"}, + {BUF_VIDEO_ULTI, CODEC_ID_ULTI, "IBM UltiMotion (ffmpeg)"}, + {BUF_VIDEO_WNV1, CODEC_ID_WNV1, "Winnow Video (ffmpeg)"}, + {BUF_VIDEO_XL, CODEC_ID_VIXL, "Miro/Pinnacle VideoXL (ffmpeg)"}, + {BUF_VIDEO_RT21, CODEC_ID_INDEO2, "Indeo/RealTime 2 (ffmpeg)"}, + {BUF_VIDEO_FPS1, CODEC_ID_FRAPS, "Fraps (ffmpeg)"}, + {BUF_VIDEO_MPEG, CODEC_ID_MPEG1VIDEO, "MPEG 1/2 (ffmpeg)"}, + {BUF_VIDEO_CSCD, CODEC_ID_CSCD, "CamStudio (ffmpeg)"}, + {BUF_VIDEO_AVS, CODEC_ID_AVS, "AVS (ffmpeg)"}, + {BUF_VIDEO_ALGMM, CODEC_ID_MMVIDEO, "American Laser Games MM (ffmpeg)"}, + {BUF_VIDEO_ZMBV, CODEC_ID_ZMBV, "Zip Motion Blocks Video (ffmpeg)"}, + {BUF_VIDEO_SMACKER, CODEC_ID_SMACKVIDEO, "Smacker (ffmpeg)"}, + {BUF_VIDEO_NUV, CODEC_ID_NUV, "NuppelVideo (ffmpeg)"}, + {BUF_VIDEO_KMVC, CODEC_ID_KMVC, "Karl Morton's Video Codec (ffmpeg)"}, + {BUF_VIDEO_FLASHSV, CODEC_ID_FLASHSV, "Flash Screen Video (ffmpeg)"}, + {BUF_VIDEO_CAVS, CODEC_ID_CAVS, "Chinese AVS (ffmpeg)"}, + {BUF_VIDEO_VMNC, CODEC_ID_VMNC, "VMware Screen Codec (ffmpeg)"}, + {BUF_VIDEO_THEORA_RAW, CODEC_ID_THEORA, "Theora (ffmpeg)"}, +}; + +static const char *const skip_loop_filter_enum_names[] = { + "default", /* AVDISCARD_DEFAULT */ + "none", /* AVDISCARD_NONE */ + "nonref", /* AVDISCARD_NONREF */ + "bidir", /* AVDISCARD_BIDIR */ + "nonkey", /* AVDISCARD_NONKEY */ + "all", /* AVDISCARD_ALL */ + NULL +}; + +static const int skip_loop_filter_enum_values[] = { + AVDISCARD_DEFAULT, + AVDISCARD_NONE, + AVDISCARD_NONREF, + AVDISCARD_BIDIR, + AVDISCARD_NONKEY, + AVDISCARD_ALL +}; + +static void init_video_codec (ff_video_decoder_t *this, unsigned int codec_type) { + size_t i; + + /* find the decoder */ + this->codec = NULL; + + for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++) + if(ff_video_lookup[i].type == codec_type) { + pthread_mutex_lock(&ffmpeg_lock); + this->codec = avcodec_find_decoder(ff_video_lookup[i].id); + pthread_mutex_unlock(&ffmpeg_lock); + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, + ff_video_lookup[i].name); + break; + } + + if (!this->codec) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), + codec_type); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); + return; + } + + lprintf("lavc decoder found\n"); + + /* force (width % 8 == 0), otherwise there will be + * display problems with Xv. + */ + this->bih.biWidth = (this->bih.biWidth + 1) & (~1); + + this->context->width = this->bih.biWidth; + this->context->height = this->bih.biHeight; + this->context->stream_codec_tag = this->context->codec_tag = + _x_stream_info_get(this->stream, XINE_STREAM_INFO_VIDEO_FOURCC); + + + /* Some codecs (eg rv10) copy flags in init so it's necessary to set + * this flag here in case we are going to use direct rendering */ + if(this->codec->capabilities & CODEC_CAP_DR1) { + this->context->flags |= CODEC_FLAG_EMU_EDGE; + } + + if (this->class->choose_speed_over_accuracy) + this->context->flags2 |= CODEC_FLAG2_FAST; + + pthread_mutex_lock(&ffmpeg_lock); + if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock(&ffmpeg_lock); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: couldn't open decoder\n")); + free(this->context); + this->context = NULL; + _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); + return; + } + + if (this->class->thread_count > 1) { + avcodec_thread_init(this->context, this->class->thread_count); + this->context->thread_count = this->class->thread_count; + } + + this->context->skip_loop_filter = skip_loop_filter_enum_values[this->class->skip_loop_filter_enum]; + + pthread_mutex_unlock(&ffmpeg_lock); + + lprintf("lavc decoder opened\n"); + + this->decoder_ok = 1; + + if ((codec_type != BUF_VIDEO_MPEG) && + (codec_type != BUF_VIDEO_DV)) { + + if (!this->bih.biWidth || !this->bih.biHeight) { + this->bih.biWidth = this->context->width; + this->bih.biHeight = this->context->height; + } + + + set_stream_info(this); + } + + (this->stream->video_out->open) (this->stream->video_out, this->stream); + + this->skipframes = 0; + + /* enable direct rendering by default */ + this->output_format = XINE_IMGFMT_YV12; +#ifdef ENABLE_DIRECT_RENDERING + if( this->codec->capabilities & CODEC_CAP_DR1 && this->codec->id != CODEC_ID_H264 ) { + this->context->get_buffer = get_buffer; + this->context->release_buffer = release_buffer; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: direct rendering enabled\n")); + } +#endif + + /* flag for interlaced streams */ + this->frame_flags = 0; + /* FIXME: which codecs can be interlaced? + FIXME: check interlaced DCT and other codec specific info. */ + switch( codec_type ) { + case BUF_VIDEO_DV: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_MPEG: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_MJPEG: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_HUFFYUV: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + case BUF_VIDEO_H264: + this->frame_flags |= VO_INTERLACED_FLAG; + break; + } + +} + +static void choose_speed_over_accuracy_cb(void *user_data, xine_cfg_entry_t *entry) { + ff_video_class_t *class = (ff_video_class_t *) user_data; + + class->choose_speed_over_accuracy = entry->num_value; +} + +static void skip_loop_filter_enum_cb(void *user_data, xine_cfg_entry_t *entry) { + ff_video_class_t *class = (ff_video_class_t *) user_data; + + class->skip_loop_filter_enum = entry->num_value; +} + +static void thread_count_cb(void *user_data, xine_cfg_entry_t *entry) { + ff_video_class_t *class = (ff_video_class_t *) user_data; + + class->thread_count = entry->num_value; +} + +static void pp_quality_cb(void *user_data, xine_cfg_entry_t *entry) { + ff_video_class_t *class = (ff_video_class_t *) user_data; + + class->pp_quality = entry->num_value; +} + +static void pp_change_quality (ff_video_decoder_t *this) { + this->pp_quality = this->class->pp_quality; + + if(this->pp_available && this->pp_quality) { + if(!this->pp_context && this->context) + this->pp_context = pp_get_context(this->context->width, this->context->height, + this->pp_flags); + if(this->pp_mode) + pp_free_mode(this->pp_mode); + + this->pp_mode = pp_get_mode_by_name_and_quality("hb:a,vb:a,dr:a", + this->pp_quality); + } else { + if(this->pp_mode) { + pp_free_mode(this->pp_mode); + this->pp_mode = NULL; + } + + if(this->pp_context) { + pp_free_context(this->pp_context); + this->pp_context = NULL; + } + } +} + +static void init_postprocess (ff_video_decoder_t *this) { + uint32_t cpu_caps; + + /* Allow post processing on mpeg-4 (based) codecs */ + switch(this->codec->id) { + case CODEC_ID_MPEG4: + case CODEC_ID_MSMPEG4V1: + case CODEC_ID_MSMPEG4V2: + case CODEC_ID_MSMPEG4V3: + case CODEC_ID_WMV1: + case CODEC_ID_WMV2: + this->pp_available = 1; + break; + default: + this->pp_available = 0; + break; + } + + /* Detect what cpu accel we have */ + cpu_caps = xine_mm_accel(); + this->pp_flags = PP_FORMAT_420; + + if(cpu_caps & MM_ACCEL_X86_MMX) + this->pp_flags |= PP_CPU_CAPS_MMX; + + if(cpu_caps & MM_ACCEL_X86_MMXEXT) + this->pp_flags |= PP_CPU_CAPS_MMX2; + + if(cpu_caps & MM_ACCEL_X86_3DNOW) + this->pp_flags |= PP_CPU_CAPS_3DNOW; + + /* Set level */ + pp_change_quality(this); +} + +static int ff_handle_mpeg_sequence(ff_video_decoder_t *this, mpeg_parser_t *parser) { + + /* + * init codec + */ + if (this->decoder_init_mode) { + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, + "mpeg-1 (ffmpeg)"); + + init_video_codec (this, BUF_VIDEO_MPEG); + this->decoder_init_mode = 0; + } + + /* frame format change */ + if ((parser->width != this->bih.biWidth) || + (parser->height != this->bih.biHeight) || + (parser->frame_aspect_ratio != this->aspect_ratio)) { + xine_event_t event; + xine_format_change_data_t data; + + this->bih.biWidth = parser->width; + this->bih.biHeight = parser->height; + this->aspect_ratio = parser->frame_aspect_ratio; + this->aspect_ratio_prio = 2; + lprintf("mpeg seq aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + + event.type = XINE_EVENT_FRAME_FORMAT_CHANGE; + event.stream = this->stream; + event.data = &data; + event.data_length = sizeof(data); + data.width = this->bih.biWidth; + data.height = this->bih.biHeight; + data.aspect = this->aspect_ratio; + data.pan_scan = 0; + xine_event_send(this->stream, &event); + } + this->video_step = this->mpeg_parser->frame_duration; + + return 1; +} + +static void ff_convert_frame(ff_video_decoder_t *this, vo_frame_t *img) { + int y; + uint8_t *dy, *du, *dv, *sy, *su, *sv; + + dy = img->base[0]; + du = img->base[1]; + dv = img->base[2]; + sy = this->av_frame->data[0]; + su = this->av_frame->data[1]; + sv = this->av_frame->data[2]; + + if (this->context->pix_fmt == PIX_FMT_YUV410P) { + + yuv9_to_yv12( + /* Y */ + this->av_frame->data[0], + this->av_frame->linesize[0], + img->base[0], + img->pitches[0], + /* U */ + this->av_frame->data[1], + this->av_frame->linesize[1], + img->base[1], + img->pitches[1], + /* V */ + this->av_frame->data[2], + this->av_frame->linesize[2], + img->base[2], + img->pitches[2], + /* width x height */ + img->width, + img->height); + + } else if (this->context->pix_fmt == PIX_FMT_YUV411P) { + + yuv411_to_yv12( + /* Y */ + this->av_frame->data[0], + this->av_frame->linesize[0], + img->base[0], + img->pitches[0], + /* U */ + this->av_frame->data[1], + this->av_frame->linesize[1], + img->base[1], + img->pitches[1], + /* V */ + this->av_frame->data[2], + this->av_frame->linesize[2], + img->base[2], + img->pitches[2], + /* width x height */ + img->width, + img->height); + + } else if (this->context->pix_fmt == PIX_FMT_RGBA32) { + + int x, plane_ptr = 0; + uint32_t *argb_pixels; + uint32_t argb; + + for(y = 0; y < img->height; y++) { + argb_pixels = (uint32_t *)sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + /* this is endian-safe as the ARGB pixels are stored in + * machine order */ + argb = *argb_pixels++; + r = (argb >> 16) & 0xFF; + g = (argb >> 8) & 0xFF; + b = (argb >> 0) & 0xFF; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_RGB565) { + + int x, plane_ptr = 0; + uint8_t *src; + uint16_t pixel16; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + /* a 16-bit RGB565 pixel is supposed to be stored in native-endian + * byte order; the following should be endian-safe */ + pixel16 = *((uint16_t *)src); + src += 2; + b = (pixel16 << 3) & 0xFF; + g = (pixel16 >> 3) & 0xFF; + r = (pixel16 >> 8) & 0xFF; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_RGB555) { + + int x, plane_ptr = 0; + uint8_t *src; + uint16_t pixel16; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + /* a 16-bit RGB555 pixel is supposed to be stored in native-endian + * byte order; the following should be endian-safe */ + pixel16 = *((uint16_t *)src); + src += 2; + b = (pixel16 << 3) & 0xFF; + g = (pixel16 >> 2) & 0xFF; + r = (pixel16 >> 7) & 0xFF; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_BGR24) { + + int x, plane_ptr = 0; + uint8_t *src; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + b = *src++; + g = *src++; + r = *src++; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_RGB24) { + + int x, plane_ptr = 0; + uint8_t *src; + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + uint8_t r, g, b; + + r = *src++; + g = *src++; + b = *src++; + + this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); + this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); + this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else if (this->context->pix_fmt == PIX_FMT_PAL8) { + + int x, plane_ptr = 0; + uint8_t *src; + uint8_t pixel; + uint32_t *palette32 = (uint32_t *)su; /* palette is in data[1] */ + uint32_t rgb_color; + uint8_t r, g, b; + uint8_t y_palette[256]; + uint8_t u_palette[256]; + uint8_t v_palette[256]; + + for (x = 0; x < 256; x++) { + rgb_color = palette32[x]; + b = rgb_color & 0xFF; + rgb_color >>= 8; + g = rgb_color & 0xFF; + rgb_color >>= 8; + r = rgb_color & 0xFF; + y_palette[x] = COMPUTE_Y(r, g, b); + u_palette[x] = COMPUTE_U(r, g, b); + v_palette[x] = COMPUTE_V(r, g, b); + } + + for(y = 0; y < img->height; y++) { + src = sy; + for(x = 0; x < img->width; x++) { + pixel = *src++; + + this->yuv.y[plane_ptr] = y_palette[pixel]; + this->yuv.u[plane_ptr] = u_palette[pixel]; + this->yuv.v[plane_ptr] = v_palette[pixel]; + plane_ptr++; + } + sy += this->av_frame->linesize[0]; + } + + yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); + + } else { + + for (y=0; yheight; y++) { + xine_fast_memcpy (dy, sy, img->width); + + dy += img->pitches[0]; + + sy += this->av_frame->linesize[0]; + } + + for (y=0; y<(img->height/2); y++) { + + if (this->context->pix_fmt != PIX_FMT_YUV444P) { + + xine_fast_memcpy (du, su, img->width/2); + xine_fast_memcpy (dv, sv, img->width/2); + + } else { + + int x; + uint8_t *src; + uint8_t *dst; + + /* subsample */ + + src = su; dst = du; + for (x=0; x<(img->width/2); x++) { + *dst = *src; + dst++; + src += 2; + } + src = sv; dst = dv; + for (x=0; x<(img->width/2); x++) { + *dst = *src; + dst++; + src += 2; + } + + } + + du += img->pitches[1]; + dv += img->pitches[2]; + + if (this->context->pix_fmt != PIX_FMT_YUV420P) { + su += 2*this->av_frame->linesize[1]; + sv += 2*this->av_frame->linesize[2]; + } else { + su += this->av_frame->linesize[1]; + sv += this->av_frame->linesize[2]; + } + } + } +} + +static void ff_check_bufsize (ff_video_decoder_t *this, int size) { + if (size > this->bufsize) { + this->bufsize = size + size / 2; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc(this->buf, this->bufsize + FF_INPUT_BUFFER_PADDING_SIZE ); + } +} + +static void ff_handle_preview_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + int codec_type; + + lprintf ("preview buffer\n"); + + codec_type = buf->type & 0xFFFF0000; + if (codec_type == BUF_VIDEO_MPEG) { + this->is_mpeg12 = 1; + if ( this->mpeg_parser == NULL ) { + this->mpeg_parser = xine_xmalloc(sizeof(mpeg_parser_t)); + mpeg_parser_init(this->mpeg_parser); + this->decoder_init_mode = 0; + } + } + + if (this->decoder_init_mode && !this->is_mpeg12) { + init_video_codec(this, codec_type); + init_postprocess(this); + this->decoder_init_mode = 0; + } +} + +static void ff_handle_header_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + + lprintf ("header buffer\n"); + + /* accumulate data */ + ff_check_bufsize(this, this->size + buf->size); + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + int codec_type; + + lprintf ("header complete\n"); + codec_type = buf->type & 0xFFFF0000; + + if (buf->decoder_flags & BUF_FLAG_STDHEADER) { + + lprintf("standard header\n"); + + /* init package containing bih */ + memcpy ( &this->bih, this->buf, sizeof(xine_bmiheader) ); + + if (this->bih.biSize > sizeof(xine_bmiheader)) { + this->context->extradata_size = this->bih.biSize - sizeof(xine_bmiheader); + this->context->extradata = malloc(this->context->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, this->buf + sizeof(xine_bmiheader), + this->context->extradata_size); + } + + this->context->bits_per_sample = this->bih.biBitCount; + + } else { + + switch (codec_type) { + case BUF_VIDEO_RV10: + case BUF_VIDEO_RV20: + this->bih.biWidth = _X_BE_16(&this->buf[12]); + this->bih.biHeight = _X_BE_16(&this->buf[14]); + + this->context->sub_id = _X_BE_32(&this->buf[30]); + + this->context->slice_offset = xine_xmalloc(sizeof(int)*SLICE_OFFSET_SIZE); + this->slice_offset_size = SLICE_OFFSET_SIZE; + + lprintf("w=%d, h=%d\n", this->bih.biWidth, this->bih.biHeight); + + break; + default: + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_video_dec: unknown header for buf type 0x%X\n", codec_type); + return; + } + } + + /* reset accumulator */ + this->size = 0; + } +} + +static void ff_handle_special_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + /* take care of all the various types of special buffers + * note that order is important here */ + lprintf("special buffer\n"); + + if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM && + !this->context->extradata_size) { + + lprintf("BUF_SPECIAL_STSD_ATOM\n"); + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = xine_xmalloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + + } else if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG && + !this->context->extradata_size) { + + lprintf("BUF_SPECIAL_DECODER_CONFIG\n"); + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = xine_xmalloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + + } else if (buf->decoder_info[1] == BUF_SPECIAL_PALETTE) { + unsigned int i; + + palette_entry_t *demuxer_palette; + AVPaletteControl *decoder_palette; + + lprintf("BUF_SPECIAL_PALETTE\n"); + this->context->palctrl = &this->palette_control; + decoder_palette = (AVPaletteControl *)this->context->palctrl; + demuxer_palette = (palette_entry_t *)buf->decoder_info_ptr[2]; + + for (i = 0; i < buf->decoder_info[2]; i++) { + decoder_palette->palette[i] = + (demuxer_palette[i].r << 16) | + (demuxer_palette[i].g << 8) | + (demuxer_palette[i].b << 0); + } + decoder_palette->palette_changed = 1; + + } else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) { + int i; + + lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n"); + this->context->slice_count = buf->decoder_info[2]+1; + + lprintf("slice_count=%d\n", this->context->slice_count); + + if(this->context->slice_count > this->slice_offset_size) { + this->context->slice_offset = realloc(this->context->slice_offset, + sizeof(int)*this->context->slice_count); + this->slice_offset_size = this->context->slice_count; + } + + for(i = 0; i < this->context->slice_count; i++) { + this->context->slice_offset[i] = + ((uint32_t *) buf->decoder_info_ptr[2])[(2*i)+1]; + lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]); + } + } +} + +static void ff_handle_mpeg12_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + + vo_frame_t *img; + int free_img; + int got_picture, len; + int offset = 0; + int flush = 0; + int size = buf->size; + + lprintf("handle_mpeg12_buffer\n"); + + while ((size > 0) || (flush == 1)) { + + uint8_t *current; + int next_flush; + + got_picture = 0; + if (!flush) { + current = mpeg_parser_decode_data(this->mpeg_parser, + buf->content + offset, buf->content + offset + size, + &next_flush); + } else { + current = buf->content + offset + size; /* end of the buffer */ + next_flush = 0; + } + if (current == NULL) { + lprintf("current == NULL\n"); + return; + } + + if (this->mpeg_parser->has_sequence) { + ff_handle_mpeg_sequence(this, this->mpeg_parser); + } + + if (!this->decoder_ok) + return; + + if (flush) { + lprintf("flush lavc buffers\n"); + /* hack: ffmpeg outputs the last frame if size=0 */ + this->mpeg_parser->buffer_size = 0; + } + + /* skip decoding b frames if too late */ + this->context->hurry_up = (this->skipframes > 0); + + lprintf("avcodec_decode_video: size=%d\n", this->mpeg_parser->buffer_size); + len = avcodec_decode_video (this->context, this->av_frame, + &got_picture, this->mpeg_parser->chunk_buffer, + this->mpeg_parser->buffer_size); + lprintf("avcodec_decode_video: decoded_size=%d, got_picture=%d\n", + len, got_picture); + len = current - buf->content - offset; + lprintf("avcodec_decode_video: consumed_size=%d\n", len); + + flush = next_flush; + + if ((len < 0) || (len > buf->size)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_video_dec: error decompressing frame\n"); + size = 0; /* draw a bad frame and exit */ + } else { + size -= len; + offset += len; + } + + if (got_picture && this->av_frame->data[0]) { + /* got a picture, draw it */ + if(!this->av_frame->opaque) { + /* indirect rendering */ + img = this->stream->video_out->get_frame (this->stream->video_out, + this->bih.biWidth, + this->bih.biHeight, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + free_img = 1; + } else { + /* DR1 */ + img = (vo_frame_t*) this->av_frame->opaque; + free_img = 0; + } + + img->pts = this->pts; + this->pts = 0; + + if (this->av_frame->repeat_pict) + img->duration = this->video_step * 3 / 2; + else + img->duration = this->video_step; + + img->crop_right = this->crop_right; + img->crop_bottom = this->crop_bottom; + + this->skipframes = img->draw(img, this->stream); + + if(free_img) + img->free(img); + + } else { + + if (this->context->hurry_up) { + /* skipped frame, output a bad frame */ + img = this->stream->video_out->get_frame (this->stream->video_out, + this->bih.biWidth, + this->bih.biHeight, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + img->pts = 0; + img->duration = this->video_step; + img->bad_frame = 1; + this->skipframes = img->draw(img, this->stream); + img->free(img); + } + } + } +} + +static void ff_handle_buffer (ff_video_decoder_t *this, buf_element_t *buf) { + uint8_t *chunk_buf = this->buf; + AVRational avr00 = {0, 1}; + + lprintf("handle_buffer\n"); + + if (!this->decoder_ok) { + if (this->decoder_init_mode) { + int codec_type = buf->type & 0xFFFF0000; + + /* init ffmpeg decoder */ + init_video_codec(this, codec_type); + init_postprocess(this); + this->decoder_init_mode = 0; + } else { + return; + } + } + + if (buf->decoder_flags & BUF_FLAG_FRAME_START) { + lprintf("BUF_FLAG_FRAME_START\n"); + this->size = 0; + } + + /* data accumulation */ + if (buf->size > 0) { + if ((this->size == 0) && + ((buf->size + FF_INPUT_BUFFER_PADDING_SIZE) < buf->max_size) && + (buf->decoder_flags & BUF_FLAG_FRAME_END)) { + /* buf contains a complete frame */ + /* no memcpy needed */ + chunk_buf = buf->content; + this->size = buf->size; + lprintf("no memcpy needed to accumulate data\n"); + } else { + /* copy data into our internal buffer */ + ff_check_bufsize(this, this->size + buf->size); + chunk_buf = this->buf; /* ff_check_bufsize might realloc this->buf */ + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + + this->size += buf->size; + lprintf("accumulate data into this->buf\n"); + } + } + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + + vo_frame_t *img; + int free_img; + int got_picture, len; + int got_one_picture = 0; + int offset = 0; + int codec_type = buf->type & 0xFFFF0000; + int video_step_to_use = this->video_step; + + /* pad input data */ + /* note: bitstream, alt bitstream reader or something will cause + * severe mpeg4 artifacts if padding is less than 32 bits. + */ + memset(&chunk_buf[this->size], 0, FF_INPUT_BUFFER_PADDING_SIZE); + + while (this->size > 0) { + + /* DV frames can be completely skipped */ + if( codec_type == BUF_VIDEO_DV && this->skipframes ) { + this->size = 0; + got_picture = 0; + } else { + /* skip decoding b frames if too late */ + this->context->hurry_up = (this->skipframes > 0); + + lprintf("buffer size: %d\n", this->size); + len = avcodec_decode_video (this->context, this->av_frame, + &got_picture, &chunk_buf[offset], + this->size); + lprintf("consumed size: %d, got_picture: %d\n", len, got_picture); + if ((len <= 0) || (len > this->size)) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "ffmpeg_video_dec: error decompressing frame\n"); + this->size = 0; + + } else { + + offset += len; + this->size -= len; + + if (this->size > 0) { + ff_check_bufsize(this, this->size); + memmove (this->buf, &chunk_buf[offset], this->size); + chunk_buf = this->buf; + } + } + } + + /* use externally provided video_step or fall back to stream's time_base otherwise */ + video_step_to_use = (this->video_step || !this->context->time_base.den) ? this->video_step : (int)(90000ll * this->context->time_base.num / this->context->time_base.den); + + /* aspect ratio provided by ffmpeg, override previous setting */ + if ((this->aspect_ratio_prio < 2) && + av_cmp_q(this->context->sample_aspect_ratio, avr00)) { + + if (!this->bih.biWidth || !this->bih.biHeight) { + this->bih.biWidth = this->context->width; + this->bih.biHeight = this->context->height; + } + + this->aspect_ratio = av_q2d(this->context->sample_aspect_ratio) * + (double)this->bih.biWidth / (double)this->bih.biHeight; + this->aspect_ratio_prio = 2; + lprintf("ffmpeg aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + + if (got_picture && this->av_frame->data[0]) { + /* got a picture, draw it */ + got_one_picture = 1; + if(!this->av_frame->opaque) { + /* indirect rendering */ + + /* initialize the colorspace converter */ + if (!this->cs_convert_init) { + if ((this->context->pix_fmt == PIX_FMT_RGBA32) || + (this->context->pix_fmt == PIX_FMT_RGB565) || + (this->context->pix_fmt == PIX_FMT_RGB555) || + (this->context->pix_fmt == PIX_FMT_BGR24) || + (this->context->pix_fmt == PIX_FMT_RGB24) || + (this->context->pix_fmt == PIX_FMT_PAL8)) { + this->output_format = XINE_IMGFMT_YUY2; + init_yuv_planes(&this->yuv, this->bih.biWidth, this->bih.biHeight); + this->yuv_init = 1; + } + this->cs_convert_init = 1; + } + + if (this->aspect_ratio_prio == 0) { + this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight; + this->aspect_ratio_prio = 1; + lprintf("default aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + + /* xine-lib expects the framesize to be a multiple of 16x16 (macroblock) */ + img = this->stream->video_out->get_frame (this->stream->video_out, + (this->bih.biWidth + 15) & ~15, + (this->bih.biHeight + 15) & ~15, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + free_img = 1; + } else { + /* DR1 */ + img = (vo_frame_t*) this->av_frame->opaque; + free_img = 0; + } + + /* post processing */ + if(this->pp_quality != this->class->pp_quality) + pp_change_quality(this); + + if(this->pp_available && this->pp_quality) { + + if(this->av_frame->opaque) { + /* DR1 */ + img = this->stream->video_out->get_frame (this->stream->video_out, + (img->width + 15) & ~15, + (img->height + 15) & ~15, + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + free_img = 1; + } + + pp_postprocess(this->av_frame->data, this->av_frame->linesize, + img->base, img->pitches, + img->width, img->height, + this->av_frame->qscale_table, this->av_frame->qstride, + this->pp_mode, this->pp_context, + this->av_frame->pict_type); + + } else if (!this->av_frame->opaque) { + /* colorspace conversion or copy */ + ff_convert_frame(this, img); + } + + img->pts = this->pts; + this->pts = 0; + + /* workaround for weird 120fps streams */ + if( video_step_to_use == 750 ) { + /* fallback to the VIDEO_PTS_MODE */ + video_step_to_use = 0; + } + + if (this->av_frame->repeat_pict) + img->duration = video_step_to_use * 3 / 2; + else + img->duration = video_step_to_use; + + /* additionally crop away the extra pixels due to adjusting frame size above */ + img->crop_right = this->crop_right + (img->width - this->bih.biWidth); + img->crop_bottom = this->crop_bottom + (img->height - this->bih.biHeight); + + /* transfer some more frame settings for deinterlacing */ + img->progressive_frame = !this->av_frame->interlaced_frame; + img->top_field_first = this->av_frame->top_field_first; + + this->skipframes = img->draw(img, this->stream); + + if(free_img) + img->free(img); + } + } + + /* workaround for demux_mpeg_pes sending fields as frames: + * do not generate a bad frame for the first field picture + */ + if (!got_one_picture && (this->size || this->video_step || this->assume_bad_field_picture)) { + /* skipped frame, output a bad frame (use size 16x16, when size still uninitialized) */ + img = this->stream->video_out->get_frame (this->stream->video_out, + (this->bih.biWidth <= 0) ? 16 : ((this->bih.biWidth + 15) & ~15), + (this->bih.biHeight <= 0) ? 16 : ((this->bih.biHeight + 15) & ~15), + this->aspect_ratio, + this->output_format, + VO_BOTH_FIELDS|this->frame_flags); + /* set PTS to allow early syncing */ + img->pts = this->pts; + this->pts = 0; + + img->duration = video_step_to_use; + + /* additionally crop away the extra pixels due to adjusting frame size above */ + img->crop_right = ((this->bih.biWidth <= 0) ? 0 : this->crop_right) + (img->width - this->bih.biWidth); + img->crop_bottom = ((this->bih.biHeight <= 0) ? 0 : this->crop_bottom) + (img->height - this->bih.biHeight); + + img->bad_frame = 1; + this->skipframes = img->draw(img, this->stream); + img->free(img); + } + + this->assume_bad_field_picture = !got_one_picture; + } +} + +static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("processing packet type = %08x, len = %d, decoder_flags=%08x\n", + buf->type, buf->size, buf->decoder_flags); + + if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { + this->video_step = buf->decoder_info[0]; + _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); + } + + if (buf->decoder_flags & BUF_FLAG_PREVIEW) { + + ff_handle_preview_buffer(this, buf); + + } else { + + if (buf->decoder_flags & BUF_FLAG_SPECIAL) { + + ff_handle_special_buffer(this, buf); + + } + + if (buf->decoder_flags & BUF_FLAG_HEADER) { + + ff_handle_header_buffer(this, buf); + + if (buf->decoder_flags & BUF_FLAG_ASPECT) { + if (this->aspect_ratio_prio < 3) { + this->aspect_ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2]; + this->aspect_ratio_prio = 3; + lprintf("aspect ratio: %f\n", this->aspect_ratio); + set_stream_info(this); + } + } + + } else { + + /* decode */ + if (buf->pts) + this->pts = buf->pts; + + if (this->is_mpeg12) { + ff_handle_mpeg12_buffer(this, buf); + } else { + ff_handle_buffer(this, buf); + } + + } + } +} + +static void ff_flush (video_decoder_t *this_gen) { + lprintf ("ff_flush\n"); +} + +static void ff_reset (video_decoder_t *this_gen) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("ff_reset\n"); + + this->size = 0; + + if(this->context && this->decoder_ok) + avcodec_flush_buffers(this->context); + + if (this->is_mpeg12) + mpeg_parser_reset(this->mpeg_parser); +} + +static void ff_discontinuity (video_decoder_t *this_gen) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("ff_discontinuity\n"); + this->pts = 0; +} + +static void ff_dispose (video_decoder_t *this_gen) { + ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; + + lprintf ("ff_dispose\n"); + + if (this->decoder_ok) { + xine_list_iterator_t it; + AVFrame *av_frame; + + pthread_mutex_lock(&ffmpeg_lock); + avcodec_close (this->context); + pthread_mutex_unlock(&ffmpeg_lock); + + /* frame garbage collector here - workaround for buggy ffmpeg codecs that + * don't release their DR1 frames */ + while( (it = xine_list_front(this->dr1_frames)) != NULL ) + { + av_frame = (AVFrame *)xine_list_get_value(this->dr1_frames, it); + release_buffer(this->context, av_frame); + } + + this->stream->video_out->close(this->stream->video_out, this->stream); + this->decoder_ok = 0; + } + + if(this->context && this->context->slice_offset) + free(this->context->slice_offset); + + if(this->context && this->context->extradata) + free(this->context->extradata); + + if(this->yuv_init) + free_yuv_planes(&this->yuv); + + if( this->context ) + free( this->context ); + + if( this->av_frame ) + free( this->av_frame ); + + if (this->buf) + free(this->buf); + this->buf = NULL; + + if(this->pp_context) + pp_free_context(this->pp_context); + + if(this->pp_mode) + pp_free_mode(this->pp_mode); + + mpeg_parser_dispose(this->mpeg_parser); + + xine_list_delete(this->dr1_frames); + + free (this_gen); +} + +static video_decoder_t *ff_video_open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { + + ff_video_decoder_t *this ; + + lprintf ("open_plugin\n"); + + this = (ff_video_decoder_t *) xine_xmalloc (sizeof (ff_video_decoder_t)); + + this->video_decoder.decode_data = ff_decode_data; + this->video_decoder.flush = ff_flush; + this->video_decoder.reset = ff_reset; + this->video_decoder.discontinuity = ff_discontinuity; + this->video_decoder.dispose = ff_dispose; + this->size = 0; + + this->stream = stream; + this->class = (ff_video_class_t *) class_gen; + + this->av_frame = avcodec_alloc_frame(); + this->context = avcodec_alloc_context(); + this->context->opaque = this; + this->context->palctrl = NULL; + + this->decoder_ok = 0; + this->decoder_init_mode = 1; + this->buf = xine_xmalloc(VIDEOBUFSIZE + FF_INPUT_BUFFER_PADDING_SIZE); + this->bufsize = VIDEOBUFSIZE; + + this->is_mpeg12 = 0; + this->aspect_ratio = 0; + + this->pp_quality = 0; + this->pp_context = NULL; + this->pp_mode = NULL; + + this->mpeg_parser = NULL; + + this->dr1_frames = xine_list_new(); + + return &this->video_decoder; +} + +static char *ff_video_get_identifier (video_decoder_class_t *this) { + return "ffmpeg video"; +} + +static char *ff_video_get_description (video_decoder_class_t *this) { + return "ffmpeg based video decoder plugin"; +} + +static void ff_video_dispose_class (video_decoder_class_t *this) { + free (this); +} + +void *init_video_plugin (xine_t *xine, void *data) { + + ff_video_class_t *this; + config_values_t *config; + + this = (ff_video_class_t *) xine_xmalloc (sizeof (ff_video_class_t)); + + this->decoder_class.open_plugin = ff_video_open_plugin; + this->decoder_class.get_identifier = ff_video_get_identifier; + this->decoder_class.get_description = ff_video_get_description; + this->decoder_class.dispose = ff_video_dispose_class; + this->xine = xine; + + pthread_once( &once_control, init_once_routine ); + + /* Configuration for post processing quality - default to mid (3) for the + * moment */ + config = xine->config; + + this->pp_quality = xine->config->register_range(config, "video.processing.ffmpeg_pp_quality", 3, + 0, PP_QUALITY_MAX, + _("MPEG-4 postprocessing quality"), + _("You can adjust the amount of post processing applied to MPEG-4 video.\n" + "Higher values result in better quality, but need more CPU. Lower values may " + "result in image defects like block artifacts. For high quality content, " + "too heavy post processing can actually make the image worse by blurring it " + "too much."), + 10, pp_quality_cb, this); + + this->thread_count = xine->config->register_num(config, "video.processing.ffmpeg_thread_count", 1, + _("FFmpeg video decoding thread count"), + _("You can adjust the number of video decoding threads which FFmpeg may use.\n" + "Higher values should speed up decoding but it depends on the codec used " + "whether parallel decoding is supported. A rule of thumb is to have one " + "decoding thread per logical CPU (typically 1 to 4).\n" + "A change of this setting will take effect with playing the next stream."), + 10, thread_count_cb, this); + + this->skip_loop_filter_enum = xine->config->register_enum(config, "video.processing.ffmpeg_skip_loop_filter", 0, + (char **)skip_loop_filter_enum_names, + _("Skip loop filter"), + _("You can control for which frames the loop filter shall be skipped after " + "decoding.\n" + "Skipping the loop filter will speedup decoding but may lead to artefacts. " + "The number of frames for which it is skipped increases from 'none' to 'all'. " + "The default value leaves the decision up to the implementation.\n" + "A change of this setting will take effect with playing the next stream."), + 10, skip_loop_filter_enum_cb, this); + + this->choose_speed_over_accuracy = xine->config->register_bool(config, "video.processing.ffmpeg_choose_speed_over_accuracy", 0, + _("Choose speed over specification compliance"), + _("You may want to allow speed cheats which violate codec specification.\n" + "Cheating may speed up decoding but can also lead to decoding artefacts.\n" + "A change of this setting will take effect with playing the next stream."), + 10, choose_speed_over_accuracy_cb, this); + + return this; +} + +static uint32_t supported_video_types[] = { + #ifdef CONFIG_MSMPEG4V1_DECODER + BUF_VIDEO_MSMPEG4_V1, + #endif + #ifdef CONFIG_MSMPEG4V2_DECODER + BUF_VIDEO_MSMPEG4_V2, + #endif + #ifdef CONFIG_MSMPEG4V3_DECODER + BUF_VIDEO_MSMPEG4_V3, + #endif + #ifdef CONFIG_WMV1_DECODER + BUF_VIDEO_WMV7, + #endif + #ifdef CONFIG_WMV2_DECODER + BUF_VIDEO_WMV8, + #endif + #ifdef CONFIG_WMV3_DECODER + BUF_VIDEO_WMV9, + #endif + #ifdef CONFIG_VC1_DECODER + BUF_VIDEO_VC1, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_MPEG4, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_XVID, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_DIVX5, + #endif + #ifdef CONFIG_MPEG4_DECODER + BUF_VIDEO_3IVX, + #endif + #ifdef CONFIG_MJPEG_DECODER + BUF_VIDEO_JPEG, + #endif + #ifdef CONFIG_MJPEG_DECODER + BUF_VIDEO_MJPEG, + #endif + #ifdef CONFIG_MJPEGB_DECODER + BUF_VIDEO_MJPEG_B, + #endif + #ifdef CONFIG_H263I_DECODER + BUF_VIDEO_I263, + #endif + #ifdef CONFIG_H263_DECODER + BUF_VIDEO_H263, + #endif + #ifdef CONFIG_RV10_DECODER + BUF_VIDEO_RV10, + #endif + #ifdef CONFIG_RV20_DECODER + BUF_VIDEO_RV20, + #endif + #ifdef CONFIG_INDEO3_DECODER + BUF_VIDEO_IV31, + #endif + #ifdef CONFIG_INDEO3_DECODER + BUF_VIDEO_IV32, + #endif + #ifdef CONFIG_SVQ1_DECODER + BUF_VIDEO_SORENSON_V1, + #endif + #ifdef CONFIG_SVQ3_DECODER + BUF_VIDEO_SORENSON_V3, + #endif + #ifdef CONFIG_DVVIDEO_DECODER + BUF_VIDEO_DV, + #endif + #ifdef CONFIG_HUFFYUV_DECODER + BUF_VIDEO_HUFFYUV, + #endif + #ifdef CONFIG_VP3_DECODER + BUF_VIDEO_VP31, + #endif + #ifdef CONFIG_VP5_DECODER + BUF_VIDEO_VP5, + #endif + #ifdef CONFIG_VP6_DECODER + BUF_VIDEO_VP6, + BUF_VIDEO_VP6F, + #endif + #ifdef CONFIG_4XM_DECODER + BUF_VIDEO_4XM, + #endif + #ifdef CONFIG_CINEPAK_DECODER + BUF_VIDEO_CINEPAK, + #endif + #ifdef CONFIG_MSVIDEO1_DECODER + BUF_VIDEO_MSVC, + #endif + #ifdef CONFIG_MSRLE_DECODER + BUF_VIDEO_MSRLE, + #endif + #ifdef CONFIG_RPZA_DECODER + BUF_VIDEO_RPZA, + #endif + #ifdef CONFIG_CYUV_DECODER + BUF_VIDEO_CYUV, + #endif + #ifdef CONFIG_ROQ_DECODER + BUF_VIDEO_ROQ, + #endif + #ifdef CONFIG_IDCIN_DECODER + BUF_VIDEO_IDCIN, + #endif + #ifdef CONFIG_XAN_WC3_DECODER + BUF_VIDEO_WC3, + #endif + #ifdef CONFIG_WS_VQA_DECODER + BUF_VIDEO_VQA, + #endif + #ifdef CONFIG_INTERPLAY_VIDEO_DECODER + BUF_VIDEO_INTERPLAY, + #endif + #ifdef CONFIG_FLIC_DECODER + BUF_VIDEO_FLI, + #endif + #ifdef CONFIG_8BPS_DECODER + BUF_VIDEO_8BPS, + #endif + #ifdef CONFIG_SMC_DECODER + BUF_VIDEO_SMC, + #endif + #ifdef CONFIG_TRUEMOTION1_DECODER + BUF_VIDEO_DUCKTM1, + #endif + #ifdef CONFIG_TRUEMOTION2_DECODER + BUF_VIDEO_DUCKTM2, + #endif + #ifdef CONFIG_VMDVIDEO_DECODER + BUF_VIDEO_VMD, + #endif + #ifdef CONFIG_ZLIB_DECODER + BUF_VIDEO_ZLIB, + #endif + #ifdef CONFIG_MSZH_DECODER + BUF_VIDEO_MSZH, + #endif + #ifdef CONFIG_ASV1_DECODER + BUF_VIDEO_ASV1, + #endif + #ifdef CONFIG_ASV2_DECODER + BUF_VIDEO_ASV2, + #endif + #ifdef CONFIG_VCR1_DECODER + BUF_VIDEO_ATIVCR1, + #endif + #ifdef CONFIG_FLV_DECODER + BUF_VIDEO_FLV1, + #endif + #ifdef CONFIG_QTRLE_DECODER + BUF_VIDEO_QTRLE, + #endif + #ifdef CONFIG_H264_DECODER + BUF_VIDEO_H264, + #endif + #ifdef CONFIG_H261_DECODER + BUF_VIDEO_H261, + #endif + #ifdef CONFIG_AASC_DECODER + BUF_VIDEO_AASC, + #endif + #ifdef CONFIG_LOCO_DECODER + BUF_VIDEO_LOCO, + #endif + #ifdef CONFIG_QDRAW_DECODER + BUF_VIDEO_QDRW, + #endif + #ifdef CONFIG_QPEG_DECODER + BUF_VIDEO_QPEG, + #endif + #ifdef CONFIG_TSCC_DECODER + BUF_VIDEO_TSCC, + #endif + #ifdef CONFIG_ULTI_DECODER + BUF_VIDEO_ULTI, + #endif + #ifdef CONFIG_WNV1_DECODER + BUF_VIDEO_WNV1, + #endif + #ifdef CONFIG_VIXL_DECODER + BUF_VIDEO_XL, + #endif + #ifdef CONFIG_INDEO2_DECODER + BUF_VIDEO_RT21, + #endif + #ifdef CONFIG_FRAPS_DECODER + BUF_VIDEO_FPS1, + #endif + #ifdef CONFIG_MPEG1VIDEO_DECODER + BUF_VIDEO_MPEG, + #endif + #ifdef CONFIG_CSCD_DECODER + BUF_VIDEO_CSCD, + #endif + #ifdef CONFIG_AVS_DECODER + BUF_VIDEO_AVS, + #endif + #ifdef CONFIG_MMVIDEO_DECODER + BUF_VIDEO_ALGMM, + #endif + #ifdef CONFIG_ZMBV_DECODER + BUF_VIDEO_ZMBV, + #endif + #ifdef CONFIG_SMACKVIDEO_DECODER + BUF_VIDEO_SMACKER, + #endif + #ifdef CONFIG_NUV_DECODER + BUF_VIDEO_NUV, + #endif + #ifdef CONFIG_KMVC_DECODER + BUF_VIDEO_KMVC, + #endif + #ifdef CONFIG_FLASHSV_DECODER + BUF_VIDEO_FLASHSV, + #endif + #ifdef CONFIG_CAVS_DECODER + BUF_VIDEO_CAVS, + #endif + #ifdef CONFIG_VMNC_DECODER + BUF_VIDEO_VMNC, + #endif + BUF_VIDEO_THEORA_RAW, + 0 +}; + +static uint32_t wmv8_video_types[] = { + BUF_VIDEO_WMV8, + 0 +}; + +static uint32_t wmv9_video_types[] = { + BUF_VIDEO_WMV9, + 0 +}; + +decoder_info_t dec_info_ffmpeg_video = { + supported_video_types, /* supported types */ + 6 /* priority */ +}; + +decoder_info_t dec_info_ffmpeg_wmv8 = { + wmv8_video_types, /* supported types */ + 0 /* priority */ +}; + +decoder_info_t dec_info_ffmpeg_wmv9 = { + wmv9_video_types, /* supported types */ + 0 /* priority */ +}; diff --git a/src/combined/ffmpeg/ffmpeg_decoder.c b/src/combined/ffmpeg/ffmpeg_decoder.c new file mode 100644 index 000000000..776e07df9 --- /dev/null +++ b/src/combined/ffmpeg/ffmpeg_decoder.c @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2001-2004 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * xine decoder plugin using ffmpeg + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "../../libffmpeg/ffmpeg_config.h" +#endif + +#include "xine_internal.h" + +#include "ffmpeg_decoder.h" + +/* + * common initialisation + */ + +pthread_once_t once_control = PTHREAD_ONCE_INIT; +pthread_mutex_t ffmpeg_lock; + +#ifndef HAVE_FFMPEG + +#define REGISTER_ENCODER(X,x) \ + if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder) +#define REGISTER_DECODER(X,x) \ + if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder) +#define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x) + +#define REGISTER_PARSER(X,x) \ + if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser) + +/* If you do not call this function, then you can select exactly which + formats you want to support */ + +/** + * simple call to register all the codecs. + */ +void avcodec_register_all(void) +{ + static int inited = 0; + + if (inited != 0) + return; + inited = 1; + + /* video codecs */ + REGISTER_DECODER(AASC, aasc); + REGISTER_ENCDEC (ASV1, asv1); + REGISTER_ENCDEC (ASV2, asv2); + REGISTER_DECODER(AVS, avs); + REGISTER_DECODER(BMP, bmp); + REGISTER_DECODER(CAVS, cavs); + REGISTER_DECODER(CINEPAK, cinepak); + REGISTER_DECODER(CLJR, cljr); + REGISTER_DECODER(CSCD, cscd); + REGISTER_DECODER(CYUV, cyuv); + REGISTER_DECODER(DSICINVIDEO, dsicinvideo); + REGISTER_ENCDEC (DVVIDEO, dvvideo); + REGISTER_DECODER(EIGHTBPS, eightbps); + REGISTER_ENCDEC (FFV1, ffv1); + REGISTER_ENCDEC (FFVHUFF, ffvhuff); + REGISTER_DECODER(FLASHSV, flashsv); + REGISTER_DECODER(FLIC, flic); + REGISTER_ENCDEC (FLV, flv); + REGISTER_DECODER(FOURXM, fourxm); + REGISTER_DECODER(FRAPS, fraps); + REGISTER_ENCDEC (GIF, gif); + REGISTER_ENCDEC (H261, h261); + REGISTER_ENCDEC (H263, h263); + REGISTER_DECODER(H263I, h263i); + REGISTER_ENCODER(H263P, h263p); + REGISTER_DECODER(H264, h264); + REGISTER_ENCDEC (HUFFYUV, huffyuv); + REGISTER_DECODER(IDCIN, idcin); + REGISTER_DECODER(INDEO2, indeo2); + REGISTER_DECODER(INDEO3, indeo3); + REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video); + REGISTER_ENCODER(JPEGLS, jpegls); + REGISTER_DECODER(KMVC, kmvc); + REGISTER_ENCODER(LJPEG, ljpeg); + REGISTER_DECODER(LOCO, loco); + REGISTER_DECODER(MDEC, mdec); + REGISTER_ENCDEC (MJPEG, mjpeg); + REGISTER_DECODER(MJPEGB, mjpegb); + REGISTER_DECODER(MMVIDEO, mmvideo); +#ifdef HAVE_XVMC + REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc); +#endif + REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); + REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); + REGISTER_ENCDEC (MPEG4, mpeg4); + REGISTER_DECODER(MPEGVIDEO, mpegvideo); + REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); + REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); + REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); + REGISTER_DECODER(MSRLE, msrle); + REGISTER_DECODER(MSVIDEO1, msvideo1); + REGISTER_DECODER(MSZH, mszh); + REGISTER_DECODER(NUV, nuv); + REGISTER_ENCODER(PAM, pam); + REGISTER_ENCODER(PBM, pbm); + REGISTER_ENCODER(PGM, pgm); + REGISTER_ENCODER(PGMYUV, pgmyuv); +#ifdef CONFIG_ZLIB + REGISTER_ENCDEC (PNG, png); +#endif + REGISTER_ENCODER(PPM, ppm); + REGISTER_DECODER(QDRAW, qdraw); + REGISTER_DECODER(QPEG, qpeg); + REGISTER_DECODER(QTRLE, qtrle); + REGISTER_ENCDEC (RAWVIDEO, rawvideo); + REGISTER_DECODER(ROQ, roq); + REGISTER_DECODER(RPZA, rpza); + REGISTER_ENCDEC (RV10, rv10); + REGISTER_ENCDEC (RV20, rv20); + REGISTER_DECODER(SMACKER, smacker); + REGISTER_DECODER(SMC, smc); + REGISTER_ENCDEC (SNOW, snow); + REGISTER_DECODER(SP5X, sp5x); + REGISTER_ENCDEC (SVQ1, svq1); + REGISTER_DECODER(SVQ3, svq3); + REGISTER_DECODER(TARGA, targa); + REGISTER_DECODER(THEORA, theora); + REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo); + REGISTER_DECODER(TIFF, tiff); + REGISTER_DECODER(TRUEMOTION1, truemotion1); + REGISTER_DECODER(TRUEMOTION2, truemotion2); + REGISTER_DECODER(TSCC, tscc); + REGISTER_DECODER(ULTI, ulti); + REGISTER_DECODER(VC1, vc1); + REGISTER_DECODER(VCR1, vcr1); + REGISTER_DECODER(VMDVIDEO, vmdvideo); + REGISTER_DECODER(VMNC, vmnc); + REGISTER_DECODER(VP3, vp3); + REGISTER_DECODER(VP5, vp5); + REGISTER_DECODER(VP6, vp6); + REGISTER_DECODER(VP6F, vp6f); + REGISTER_DECODER(VQA, vqa); + REGISTER_ENCDEC (WMV1, wmv1); + REGISTER_ENCDEC (WMV2, wmv2); + REGISTER_DECODER(WMV3, wmv3); + REGISTER_DECODER(WNV1, wnv1); +#ifdef CONFIG_X264 + REGISTER_ENCODER(X264, x264); +#endif + REGISTER_DECODER(XAN_WC3, xan_wc3); + REGISTER_DECODER(XL, xl); +#ifdef CONFIG_XVID + REGISTER_ENCODER(XVID, xvid); +#endif + REGISTER_ENCDEC (ZLIB, zlib); +#ifdef CONFIG_ZLIB + REGISTER_ENCDEC (ZMBV, zmbv); +#endif + + /* audio codecs */ +#ifdef CONFIG_LIBFAAD + REGISTER_DECODER(AAC, aac); + REGISTER_DECODER(MPEG4AAC, mpeg4aac); +#endif +#ifdef CONFIG_LIBA52 + REGISTER_DECODER(AC3, ac3); +#endif + REGISTER_ENCODER(AC3, ac3); + REGISTER_DECODER(ALAC, alac); +#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) + REGISTER_ENCDEC (AMR_NB, amr_nb); +#endif +#ifdef CONFIG_AMR_WB + REGISTER_ENCDEC (AMR_WB, amr_wb); +#endif + REGISTER_DECODER(COOK, cook); + REGISTER_DECODER(DSICINAUDIO, dsicinaudio); +#ifdef CONFIG_LIBDTS + REGISTER_DECODER(DTS, dts); +#endif +#ifdef CONFIG_LIBFAAC + REGISTER_ENCODER(FAAC, faac); +#endif + REGISTER_ENCDEC (FLAC, flac); + REGISTER_DECODER(IMC, imc); +#ifdef CONFIG_LIBGSM + REGISTER_ENCDEC (LIBGSM, libgsm); +#endif + REGISTER_DECODER(MACE3, mace3); + REGISTER_DECODER(MACE6, mace6); + REGISTER_ENCDEC (MP2, mp2); + REGISTER_DECODER(MP3, mp3); + REGISTER_DECODER(MP3ADU, mp3adu); +#ifdef CONFIG_LIBMP3LAME + REGISTER_ENCODER(MP3LAME, mp3lame); +#endif + REGISTER_DECODER(MP3ON4, mp3on4); + REGISTER_DECODER(MPC7, mpc7); +#ifdef CONFIG_LIBVORBIS + if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis); + if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis); +#endif + REGISTER_DECODER(QDM2, qdm2); + REGISTER_DECODER(RA_144, ra_144); + REGISTER_DECODER(RA_288, ra_288); + REGISTER_DECODER(SHORTEN, shorten); + REGISTER_DECODER(SMACKAUD, smackaud); + REGISTER_ENCDEC (SONIC, sonic); + REGISTER_ENCODER(SONIC_LS, sonic_ls); + REGISTER_DECODER(TRUESPEECH, truespeech); + REGISTER_DECODER(TTA, tta); + REGISTER_DECODER(VMDAUDIO, vmdaudio); + REGISTER_ENCDEC (VORBIS, vorbis); + REGISTER_DECODER(WAVPACK, wavpack); + REGISTER_DECODER(WMAV1, wmav1); + REGISTER_DECODER(WMAV2, wmav2); + REGISTER_DECODER(WS_SND1, ws_snd1); + + /* pcm codecs */ + REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); + REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); + REGISTER_ENCDEC (PCM_S8, pcm_s8); + REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); + REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); + REGISTER_ENCDEC (PCM_S24BE, pcm_s24be); + REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud); + REGISTER_ENCDEC (PCM_S24LE, pcm_s24le); + REGISTER_ENCDEC (PCM_S32BE, pcm_s32be); + REGISTER_ENCDEC (PCM_S32LE, pcm_s32le); + REGISTER_ENCDEC (PCM_U8, pcm_u8); + REGISTER_ENCDEC (PCM_U16BE, pcm_u16be); + REGISTER_ENCDEC (PCM_U16LE, pcm_u16le); + REGISTER_ENCDEC (PCM_U24BE, pcm_u24be); + REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); + REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); + REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); + + /* dpcm codecs */ + REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm); + REGISTER_DECODER(ROQ_DPCM, roq_dpcm); + REGISTER_DECODER(SOL_DPCM, sol_dpcm); + REGISTER_DECODER(XAN_DPCM, xan_dpcm); + + /* adpcm codecs */ + REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm); + REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx); + REGISTER_ENCDEC (ADPCM_CT, adpcm_ct); + REGISTER_ENCDEC (ADPCM_EA, adpcm_ea); + REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); + REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3); + REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4); + REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt); + REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); + REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); + REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws); + REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); + REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2); + REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3); + REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4); + REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf); + REGISTER_ENCDEC (ADPCM_XA, adpcm_xa); + REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha); + + /* subtitles */ + REGISTER_ENCDEC (DVBSUB, dvbsub); + REGISTER_ENCDEC (DVDSUB, dvdsub); + + /* parsers */ + REGISTER_PARSER (AAC, aac); + REGISTER_PARSER (AC3, ac3); + REGISTER_PARSER (CAVSVIDEO, cavsvideo); + REGISTER_PARSER (DVBSUB, dvbsub); + REGISTER_PARSER (DVDSUB, dvdsub); + REGISTER_PARSER (H261, h261); + REGISTER_PARSER (H263, h263); + REGISTER_PARSER (H264, h264); + REGISTER_PARSER (MJPEG, mjpeg); + REGISTER_PARSER (MPEG4VIDEO, mpeg4video); + REGISTER_PARSER (MPEGAUDIO, mpegaudio); + REGISTER_PARSER (MPEGVIDEO, mpegvideo); + REGISTER_PARSER (PNM, pnm); + + /* + av_register_bitstream_filter(&dump_extradata_bsf); + av_register_bitstream_filter(&remove_extradata_bsf); + av_register_bitstream_filter(&noise_bsf); + av_register_bitstream_filter(&mp3_header_compress_bsf); + av_register_bitstream_filter(&mp3_header_decompress_bsf); + av_register_bitstream_filter(&mjpega_dump_header_bsf); + */ +} + +#endif + +void init_once_routine(void) { + pthread_mutex_init(&ffmpeg_lock, NULL); + avcodec_init(); + avcodec_register_all(); +} + +/* + * exported plugin catalog entry + */ + +const plugin_info_t xine_plugin_info[] EXPORTED = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_VIDEO_DECODER | PLUGIN_MUST_PRELOAD, 18, "ffmpegvideo", XINE_VERSION_CODE, &dec_info_ffmpeg_video, init_video_plugin }, + { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv8", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv8, init_video_plugin }, + { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv9", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv9, init_video_plugin }, + { PLUGIN_AUDIO_DECODER, 15, "ffmpegaudio", XINE_VERSION_CODE, &dec_info_ffmpeg_audio, init_audio_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; diff --git a/src/combined/ffmpeg/ffmpeg_decoder.h b/src/combined/ffmpeg/ffmpeg_decoder.h new file mode 100644 index 000000000..f47421253 --- /dev/null +++ b/src/combined/ffmpeg/ffmpeg_decoder.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2001-2005 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + */ + +#ifndef HAVE_XINE_DECODER_H +#define HAVE_XINE_DECODER_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_FFMPEG_AVUTIL_H +# include +#elif defined HAVE_FFMPEG +# include +#else +# include "../../libffmpeg/libavcodec/avcodec.h" +#endif + +typedef struct ff_codec_s { + uint32_t type; + enum CodecID id; + const char *name; +} ff_codec_t; + +void *init_audio_plugin (xine_t *xine, void *data); +void *init_video_plugin (xine_t *xine, void *data); + +extern decoder_info_t dec_info_ffmpeg_video; +extern decoder_info_t dec_info_ffmpeg_wmv8; +extern decoder_info_t dec_info_ffmpeg_wmv9; +extern decoder_info_t dec_info_ffmpeg_audio; + +extern pthread_once_t once_control; +void init_once_routine(void); + +extern pthread_mutex_t ffmpeg_lock; + +#endif diff --git a/src/combined/ffmpeg/ffmpeg_encoder.c b/src/combined/ffmpeg/ffmpeg_encoder.c new file mode 100644 index 000000000..2d1be10a3 --- /dev/null +++ b/src/combined/ffmpeg/ffmpeg_encoder.c @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2000-2004 the xine project + * + * This file is part of xine, a unix video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + */ + +/* mpeg encoders for the dxr3 video out plugin. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define LOG_MODULE "dxr3_mpeg_encoder" +/* #define LOG_VERBOSE */ +/* #define LOG */ + +#include "video_out_dxr3.h" + +#ifdef HAVE_FFMPEG_AVUTIL_H +# include +#elif defined HAVE_FFMPEG +# include +#else +# include "../../libffmpeg/libavcodec/avcodec.h" +#endif + +/* buffer size for encoded mpeg1 stream; will hold one intra frame + * at 640x480 typical sizes are <50 kB. 512 kB should be plenty */ +#define DEFAULT_BUFFER_SIZE 512*1024 + + +/*initialisation function, used by the dxr3 plugin */ +int dxr3_encoder_init(dxr3_driver_t *drv) EXPORTED; + +/* functions required by encoder api */ +static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame); +static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame); +static int lavc_on_unneeded(dxr3_driver_t *drv); + +/*encoder structure*/ +typedef struct lavc_data_s { + encoder_data_t encoder_data; + AVCodecContext *context; /* handle for encoding */ + int width, height; /* width and height of the video frame */ + uint8_t *ffmpeg_buffer; /* lavc buffer */ + AVFrame *picture; /* picture to be encoded */ + uint8_t *out[3]; /* aligned buffer for YV12 data */ + uint8_t *buf; /* unaligned YV12 buffer */ +} lavc_data_t; + + +int dxr3_encoder_init(dxr3_driver_t *drv) +{ + lavc_data_t* this; + avcodec_init(); + + avcodec_register_all(); + lprintf("lavc init , version %x\n", avcodec_version()); + this = xine_xmalloc(sizeof(lavc_data_t)); + if (!this) return 0; + + this->encoder_data.type = ENC_LAVC; + this->encoder_data.on_update_format = lavc_on_update_format; + this->encoder_data.on_frame_copy = NULL; + this->encoder_data.on_display_frame = lavc_on_display_frame; + this->encoder_data.on_unneeded = lavc_on_unneeded; + this->context = 0; + + drv->enc = &this->encoder_data; + return 1; +} + +/* helper function */ +static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame); + +static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame) +{ + lavc_data_t *this = (lavc_data_t *)drv->enc; + AVCodec *codec; + unsigned char use_quantizer; + + if (this->context) { + avcodec_close(this->context); + free(this->context); + free(this->picture); + this->context = NULL; + this->picture = NULL; + } + + /* if YUY2 and dimensions changed, we need to re-allocate the + * internal YV12 buffer */ + if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { + int image_size = frame->vo_frame.pitches[0] * frame->oheight; + + this->out[0] = xine_xmalloc_aligned(16, image_size * 3/2, + (void *)&this->buf); + this->out[1] = this->out[0] + image_size; + this->out[2] = this->out[1] + image_size/4; + + /* fill with black (yuv 16,128,128) */ + memset(this->out[0], 16, image_size); + memset(this->out[1], 128, image_size/4); + memset(this->out[2], 128, image_size/4); + lprintf("Using YUY2->YV12 conversion\n"); + } + + /* resolution must be a multiple of two */ + if ((frame->vo_frame.pitches[0] % 2 != 0) || (frame->oheight % 2 != 0)) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: lavc only handles video dimensions which are multiples of 2\n"); + return 0; + } + + /* get mpeg codec handle */ + codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); + if (!codec) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: lavc MPEG1 codec not found\n"); + return 0; + } + lprintf("lavc MPEG1 encoder found.\n"); + + this->width = frame->vo_frame.pitches[0]; + this->height = frame->oheight; + + this->context = avcodec_alloc_context(); + if (!this->context) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Couldn't start the ffmpeg library\n"); + return 0; + } + this->picture = avcodec_alloc_frame(); + if (!this->picture) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Couldn't allocate ffmpeg frame\n"); + return 0; + } + + /* mpeg1 encoder only support YUV420P */ + this->context->pix_fmt = PIX_FMT_YUVJ420P; + + /* put sample parameters */ + this->context->bit_rate = drv->class->xine->config->register_range(drv->class->xine->config, + "dxr3.encoding.lavc_bitrate", 10000, 1000, 20000, + _("libavcodec mpeg output bitrate (kbit/s)"), + _("The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. " + "Higher values will increase quality and CPU usage.\n" + "This setting is only considered, when constant quality mode is disabled."), 10, NULL, NULL); + this->context->bit_rate *= 1000; /* config in kbit/s, libavcodec wants bit/s */ + + use_quantizer = drv->class->xine->config->register_bool(drv->class->xine->config, + "dxr3.encoding.lavc_quantizer", 1, + _("constant quality mode"), + _("When enabled, libavcodec will use a constant quality mode by dynamically " + "compressing the images based on their complexity. When disabled, libavcodec " + "will use constant bitrate mode."), 10, NULL, NULL); + + if (use_quantizer) { + this->context->qmin = drv->class->xine->config->register_range(drv->class->xine->config, + "dxr3.encoding.lavc_qmin", 1, 1, 10, + _("minimum compression"), + _("The minimum compression to apply to an image in constant quality mode."), + 10, NULL, NULL); + + this->context->qmax = drv->class->xine->config->register_range(drv->class->xine->config, + "dxr3.encoding.lavc_qmax", 2, 1, 20, + _("maximum quantizer"), + _("The maximum compression to apply to an image in constant quality mode."), + 10, NULL, NULL); + } + + lprintf("lavc -> bitrate %d \n", this->context->bit_rate); + + this->context->width = frame->vo_frame.pitches[0]; + this->context->height = frame->oheight; + + this->context->gop_size = 0; /*intra frames only */ + this->context->me_method = ME_ZERO; /*motion estimation type*/ + + this->context->time_base.den = 90000; + if (frame->vo_frame.duration > 90000 / 24) + this->context->time_base.num = 90000 / 24; + else if (frame->vo_frame.duration < 90000 / 60) + this->context->time_base.num = 90000 / 60; + else + this->context->time_base.num = frame->vo_frame.duration; + /* ffmpeg can complain about illegal framerates, but since this seems no + * problem for the DXR3, we just tell ffmpeg to be more lax with */ + this->context->strict_std_compliance = -1; + + /* open avcodec */ + if (avcodec_open(this->context, codec) < 0) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, "dxr3_mpeg_encoder: could not open codec\n"); + return 0; + } + lprintf("dxr3_mpeg_encoder: lavc MPEG1 codec opened.\n"); + + if (!this->ffmpeg_buffer) + this->ffmpeg_buffer = (unsigned char *)malloc(DEFAULT_BUFFER_SIZE); /* why allocate more than needed ?! */ + if (!this->ffmpeg_buffer) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Couldn't allocate temp buffer for mpeg data\n"); + return 0; + } + + return 1; +} + +static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame) +{ + int size; + lavc_data_t* this = (lavc_data_t *)drv->enc; + ssize_t written; + + if (frame->vo_frame.bad_frame) return 1; + /* ignore old frames */ + if ((frame->vo_frame.pitches[0] != this->context->width) || (frame->oheight != this->context->height)) { + frame->vo_frame.free(&frame->vo_frame); + lprintf("LAVC ignoring frame !!!\n"); + return 1; + } + + /* prepare frame for conversion, handles YUY2 -> YV12 conversion when necessary */ + lavc_prepare_frame(this, drv, frame); + + /* do the encoding */ + size = avcodec_encode_video(this->context, this->ffmpeg_buffer, DEFAULT_BUFFER_SIZE, this->picture); + + frame->vo_frame.free(&frame->vo_frame); + + if (size < 0) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: encoding failed\n"); + return 0; + } + + written = write(drv->fd_video, this->ffmpeg_buffer, size); + if (written < 0) { + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: video device write failed (%s)\n", strerror(errno)); + return 0; + } + if (written != size) + xprintf(drv->class->xine, XINE_VERBOSITY_LOG, + "dxr3_mpeg_encoder: Could only write %zd of %d mpeg bytes.\n", written, size); + return 1; +} + +static int lavc_on_unneeded(dxr3_driver_t *drv) +{ + lavc_data_t *this = (lavc_data_t *)drv->enc; + lprintf("flushing buffers\n"); + if (this->context) { + avcodec_close(this->context); + free(this->context); + free(this->picture); + this->context = NULL; + this->picture = NULL; + } + return 1; +} + +static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame) +{ + int i, j, w2; + uint8_t *yuy2; + + if (frame->vo_frame.bad_frame) return 1; + + if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { + /* need YUY2->YV12 conversion */ + if (!(this->out[0] && this->out[1] && this->out[2]) ) { + lprintf("Internal YV12 buffer not created.\n"); + return 0; + } + this->picture->data[0] = this->out[0] + frame->vo_frame.pitches[0] * drv->top_bar; /* y */ + this->picture->data[1] = this->out[1] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* u */ + this->picture->data[2] = this->out[2] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* v */ + yuy2 = frame->vo_frame.base[0]; + w2 = frame->vo_frame.pitches[0] / 2; + for (i = 0; i < frame->vo_frame.height; i += 2) { + for (j = 0; j < w2; j++) { + /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */ + *(this->picture->data[0]++) = *(yuy2++); + *(this->picture->data[1]++) = *(yuy2++); + *(this->picture->data[0]++) = *(yuy2++); + *(this->picture->data[2]++) = *(yuy2++); + } + /* down sampling */ + for (j = 0; j < w2; j++) { + /* skip every second line for U and V */ + *(this->picture->data[0]++) = *(yuy2++); + yuy2++; + *(this->picture->data[0]++) = *(yuy2++); + yuy2++; + } + } + /* reset for encoder */ + this->picture->data[0] = this->out[0]; + this->picture->data[1] = this->out[1]; + this->picture->data[2] = this->out[2]; + } + else { /* YV12 **/ + this->picture->data[0] = frame->real_base[0]; + this->picture->data[1] = frame->real_base[1]; + this->picture->data[2] = frame->real_base[2]; + } + this->picture->linesize[0] = this->context->width; + this->picture->linesize[1] = this->context->width / 2; + this->picture->linesize[2] = this->context->width / 2; + return 1; +} diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am index efc1c18aa..9af34df26 100644 --- a/src/libffmpeg/Makefile.am +++ b/src/libffmpeg/Makefile.am @@ -3,46 +3,10 @@ include $(top_srcdir)/misc/Makefile.common DEFAULT_INCLUDES = -I. if HAVE_FFMPEG -AM_CFLAGS = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) -ff_cppflags = -link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) else -ff_cppflags = -I$(top_srcdir)/src/libffmpeg/libavcodec -I$(top_srcdir)/src/libffmpeg/libavutil -link_ffmpeg = \ - $(top_builddir)/src/libffmpeg/libavcodec/libavcodec.la \ - $(top_builddir)/src/libffmpeg/libavutil/libavutil.la \ - $(top_builddir)/src/libffmpeg/libavcodec/libpostproc/libpostprocess.la SUBDIRS = libavcodec libavutil endif -# ffmpeg_config.h is generated by configure -DISTCLEANFILES = ffmpeg_config.h - -# this must always be included, even if the current machine has no DXR3... -EXTRA_DIST = ffmpeg_encoder.c diff_to_ffmpeg_cvs.txt +EXTRA_DIST = diff_to_ffmpeg_cvs.txt INTERNAL_DOCS = diff_to_ffmpeg_cvs.txt - -xineplug_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la - -if HAVE_DXR3 -AM_CPPFLAGS = -I$(top_srcdir)/src/dxr3 $(X_CFLAGS) $(ff_cppflags) \ - $(ZLIB_CPPFLAGS) -xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ - ffmpeg_encoder.c ff_mpeg_parser.c ffmpeg_decoder.h \ - ff_mpeg_parser.h -else -AM_CPPFLAGS = $(ff_cppflags) $(ZLIB_CPPFLAGS) -xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ - ff_mpeg_parser.c ffmpeg_decoder.h ff_mpeg_parser.h -endif - -xineplug_decode_ff_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -xineplug_decode_ff_la_LDFLAGS = $(xineplug_ldflags) $(IMPURE_TEXT_LDFLAGS) -xineplug_decode_ff_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm $(ZLIB_LIBS) \ - $(link_ffmpeg) $(PTHREAD_LIBS) $(LTLIBINTL) - -xineplug_decode_dvaudio_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -xineplug_decode_dvaudio_la_LDFLAGS = $(xineplug_ldflags) -xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c -xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) diff --git a/src/libffmpeg/ff_audio_decoder.c b/src/libffmpeg/ff_audio_decoder.c deleted file mode 100644 index 5f197bed5..000000000 --- a/src/libffmpeg/ff_audio_decoder.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (C) 2001-2005 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * xine audio decoder plugin using ffmpeg - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "ffmpeg_config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "ffmpeg_audio_dec" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" -#include "ffmpeg_decoder.h" - -#define AUDIOBUFSIZE (64 * 1024) - -typedef struct { - audio_decoder_class_t decoder_class; -} ff_audio_class_t; - -typedef struct ff_audio_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int output_open; - int audio_channels; - int audio_bits; - int audio_sample_rate; - - unsigned char *buf; - int bufsize; - int size; - - AVCodecContext *context; - AVCodec *codec; - - char *decode_buffer; - int decoder_ok; - -} ff_audio_decoder_t; - - -static const ff_codec_t ff_audio_lookup[] = { - {BUF_AUDIO_WMAV1, CODEC_ID_WMAV1, "MS Windows Media Audio 1 (ffmpeg)"}, - {BUF_AUDIO_WMAV2, CODEC_ID_WMAV2, "MS Windows Media Audio 2 (ffmpeg)"}, - {BUF_AUDIO_14_4, CODEC_ID_RA_144, "Real 14.4 (ffmpeg)"}, - {BUF_AUDIO_28_8, CODEC_ID_RA_288, "Real 28.8 (ffmpeg)"}, - {BUF_AUDIO_MPEG, CODEC_ID_MP3, "MP3 (ffmpeg)"}, - {BUF_AUDIO_MSADPCM, CODEC_ID_ADPCM_MS, "MS ADPCM (ffmpeg)"}, - {BUF_AUDIO_QTIMAADPCM, CODEC_ID_ADPCM_IMA_QT, "QT IMA ADPCM (ffmpeg)"}, - {BUF_AUDIO_MSIMAADPCM, CODEC_ID_ADPCM_IMA_WAV, "MS IMA ADPCM (ffmpeg)"}, - {BUF_AUDIO_DK3ADPCM, CODEC_ID_ADPCM_IMA_DK3, "Duck DK3 ADPCM (ffmpeg)"}, - {BUF_AUDIO_DK4ADPCM, CODEC_ID_ADPCM_IMA_DK4, "Duck DK4 ADPCM (ffmpeg)"}, - {BUF_AUDIO_VQA_IMA, CODEC_ID_ADPCM_IMA_WS, "Westwood Studios IMA (ffmpeg)"}, - {BUF_AUDIO_SMJPEG_IMA, CODEC_ID_ADPCM_IMA_SMJPEG, "SMJPEG IMA (ffmpeg)"}, - {BUF_AUDIO_XA_ADPCM, CODEC_ID_ADPCM_XA, "CD-ROM/XA ADPCM (ffmpeg)"}, - {BUF_AUDIO_4X_ADPCM, CODEC_ID_ADPCM_4XM, "4X ADPCM (ffmpeg)"}, - {BUF_AUDIO_EA_ADPCM, CODEC_ID_ADPCM_EA, "Electronic Arts ADPCM (ffmpeg)"}, - {BUF_AUDIO_MULAW, CODEC_ID_PCM_MULAW, "mu-law logarithmic PCM (ffmpeg)"}, - {BUF_AUDIO_ALAW, CODEC_ID_PCM_ALAW, "A-law logarithmic PCM (ffmpeg)"}, - {BUF_AUDIO_ROQ, CODEC_ID_ROQ_DPCM, "RoQ DPCM (ffmpeg)"}, - {BUF_AUDIO_INTERPLAY, CODEC_ID_INTERPLAY_DPCM, "Interplay DPCM (ffmpeg)"}, - {BUF_AUDIO_MAC3, CODEC_ID_MACE3, "MACE 3:1 (ffmpeg)"}, - {BUF_AUDIO_MAC6, CODEC_ID_MACE6, "MACE 6:1 (ffmpeg)"}, - {BUF_AUDIO_XAN_DPCM, CODEC_ID_XAN_DPCM, "Origin Xan DPCM (ffmpeg)"}, - {BUF_AUDIO_VMD, CODEC_ID_VMDAUDIO, "Sierra VMD Audio (ffmpeg)"}, - {BUF_AUDIO_FLAC, CODEC_ID_FLAC, "FLAC (ffmpeg)"}, - {BUF_AUDIO_SHORTEN, CODEC_ID_SHORTEN, "Shorten (ffmpeg)"}, - {BUF_AUDIO_ALAC, CODEC_ID_ALAC, "ALAC (ffmpeg)"}, - {BUF_AUDIO_QDESIGN2, CODEC_ID_QDM2, "QDesign (ffmpeg)"}, - {BUF_AUDIO_COOK, CODEC_ID_COOK, "RealAudio Cooker (ffmpeg)"}, - {BUF_AUDIO_TRUESPEECH, CODEC_ID_TRUESPEECH, "TrueSpeech (ffmpeg)"}, - {BUF_AUDIO_TTA, CODEC_ID_TTA, "True Audio Lossless (ffmpeg)"}, - {BUF_AUDIO_SMACKER, CODEC_ID_SMACKAUDIO, "Smacker (ffmpeg)"}, - {BUF_AUDIO_FLVADPCM, CODEC_ID_ADPCM_SWF, "Flash ADPCM (ffmpeg)"}, - {BUF_AUDIO_WAVPACK, CODEC_ID_WAVPACK, "WavPack (ffmpeg)"}, -}; - - - static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) { - if (size > this->bufsize) { - this->bufsize = size + size / 2; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } -} - -static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - int bytes_consumed; - int decode_buffer_size; - int offset; - int out; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_SPECIAL) ) { - - /* accumulate init data */ - ff_audio_ensure_buffer_size(this, this->size + buf->size); - memcpy(this->buf + this->size, buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - size_t i; - unsigned int codec_type; - xine_waveformatex *audio_header; - - codec_type = buf->type & 0xFFFF0000; - this->codec = NULL; - - for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) - if(ff_audio_lookup[i].type == codec_type) { - pthread_mutex_lock (&ffmpeg_lock); - this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); - pthread_mutex_unlock (&ffmpeg_lock); - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - ff_audio_lookup[i].name); - break; - } - - if (!this->codec) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), - codec_type); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - - this->context = avcodec_alloc_context(); - - if(buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->audio_sample_rate = buf->decoder_info[1]; - this->audio_channels = buf->decoder_info[3]; - - if(this->size) { - audio_header = (xine_waveformatex *)this->buf; - - this->context->block_align = audio_header->nBlockAlign; - this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; - - if(audio_header->cbSize > 0) { - this->context->extradata = xine_xmalloc(audio_header->cbSize); - this->context->extradata_size = audio_header->cbSize; - memcpy( this->context->extradata, - (uint8_t *)audio_header + sizeof(xine_waveformatex), - audio_header->cbSize ); - } - } - } else { - short *ptr; - - switch(codec_type) { - case BUF_AUDIO_14_4: - this->audio_sample_rate = 8000; - this->audio_channels = 1; - - this->context->block_align = 240; - break; - case BUF_AUDIO_28_8: - this->audio_sample_rate = _X_BE_16(&this->buf[0x30]); - this->audio_channels = this->buf[0x37]; - /* this->audio_bits = buf->content[0x35] */ - - this->context->block_align = _X_BE_16(&this->buf[0x2A]); - - this->context->extradata_size = 5*sizeof(short); - this->context->extradata = xine_xmalloc(this->context->extradata_size); - - ptr = (short *) this->context->extradata; - - ptr[0] = _X_BE_16(&this->buf[0x2C]); /* subpacket size */ - ptr[1] = _X_BE_16(&this->buf[0x28]); /* subpacket height */ - ptr[2] = _X_BE_16(&this->buf[0x16]); /* subpacket flavour */ - ptr[3] = _X_BE_32(&this->buf[0x18]); /* coded frame size */ - ptr[4] = 0; /* codec's data length */ - break; - default: - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type); - break; - } - } - - /* Current ffmpeg audio decoders always use 16 bits/sample - * buf->decoder_info[2] can't be used as it doesn't refer to the output - * bits/sample for some codecs (e.g. MS ADPCM) */ - this->audio_bits = 16; - - this->context->bits_per_sample = this->audio_bits; - this->context->sample_rate = this->audio_sample_rate; - this->context->channels = this->audio_channels; - this->context->codec_id = this->codec->id; - this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); - - this->size = 0; - - this->decode_buffer = xine_xmalloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); - - return; - } - } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) { - - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = xine_xmalloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); - - } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { - - if( !this->decoder_ok ) { - if ( ! this->context || ! this->codec ) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: trying to open null codec\n")); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - - pthread_mutex_lock (&ffmpeg_lock); - if (avcodec_open (this->context, this->codec) < 0) { - pthread_mutex_unlock (&ffmpeg_lock); - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: couldn't open decoder\n")); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - pthread_mutex_unlock (&ffmpeg_lock); - this->decoder_ok = 1; - } - - if (!this->output_open) { - this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, - this->stream, this->audio_bits, this->audio_sample_rate, - _x_ao_channels2mode(this->audio_channels)); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( buf->decoder_flags & BUF_FLAG_PREVIEW ) - return; - - ff_audio_ensure_buffer_size(this, this->size + buf->size); - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - - offset = 0; - while (this->size>0) { - decode_buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; - bytes_consumed = avcodec_decode_audio2 (this->context, - (int16_t *)this->decode_buffer, - &decode_buffer_size, - &this->buf[offset], - this->size); - - if (bytes_consumed<0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_audio_dec: error decompressing audio frame\n"); - this->size=0; - return; - } else if (bytes_consumed == 0 && decode_buffer_size == 0) { - if (offset) - memmove(this->buf, &this->buf[offset], this->size); - return; - } - - /* dispatch the decoded audio */ - out = 0; - while (out < decode_buffer_size) { - audio_buffer = - this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_audio_dec: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if ((decode_buffer_size - out) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = decode_buffer_size - out; - - /* fill up this buffer */ - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - - out += bytes_to_send; - } - - this->size -= bytes_consumed; - offset += bytes_consumed; - } - - /* reset internal accumulation buffer */ - this->size = 0; - } - } -} - -static void ff_audio_reset (audio_decoder_t *this_gen) { - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - - this->size = 0; - - /* try to reset the wma decoder */ - if( this->context && this->decoder_ok ) { - pthread_mutex_lock (&ffmpeg_lock); - avcodec_close (this->context); - avcodec_open (this->context, this->codec); - pthread_mutex_unlock (&ffmpeg_lock); - } -} - -static void ff_audio_discontinuity (audio_decoder_t *this_gen) { -} - -static void ff_audio_dispose (audio_decoder_t *this_gen) { - - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - - if( this->context && this->decoder_ok ) { - pthread_mutex_lock (&ffmpeg_lock); - avcodec_close (this->context); - pthread_mutex_unlock (&ffmpeg_lock); - } - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free(this->buf); - free(this->decode_buffer); - - if(this->context && this->context->extradata) - free(this->context->extradata); - - if(this->context) - free(this->context); - - free (this_gen); -} - -static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - ff_audio_decoder_t *this ; - - this = (ff_audio_decoder_t *) xine_xmalloc (sizeof (ff_audio_decoder_t)); - - this->audio_decoder.decode_data = ff_audio_decode_data; - this->audio_decoder.reset = ff_audio_reset; - this->audio_decoder.discontinuity = ff_audio_discontinuity; - this->audio_decoder.dispose = ff_audio_dispose; - - this->output_open = 0; - this->audio_channels = 0; - this->stream = stream; - this->buf = NULL; - this->size = 0; - this->bufsize = 0; - this->decoder_ok = 0; - - ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE); - - return &this->audio_decoder; -} - -static char *ff_audio_get_identifier (audio_decoder_class_t *this) { - return "ffmpeg audio"; -} - -static char *ff_audio_get_description (audio_decoder_class_t *this) { - return "ffmpeg based audio decoder plugin"; -} - -static void ff_audio_dispose_class (audio_decoder_class_t *this) { - free (this); -} - -void *init_audio_plugin (xine_t *xine, void *data) { - - ff_audio_class_t *this ; - - this = (ff_audio_class_t *) xine_xmalloc (sizeof (ff_audio_class_t)); - - this->decoder_class.open_plugin = ff_audio_open_plugin; - this->decoder_class.get_identifier = ff_audio_get_identifier; - this->decoder_class.get_description = ff_audio_get_description; - this->decoder_class.dispose = ff_audio_dispose_class; - - pthread_once( &once_control, init_once_routine ); - - return this; -} - -static uint32_t supported_audio_types[] = { - #ifdef CONFIG_WMAV1_DECODER - BUF_AUDIO_WMAV1, - #endif - #ifdef CONFIG_WMAV2_DECODER - BUF_AUDIO_WMAV2, - #endif - #ifdef CONFIG_RA_144_DECODER - BUF_AUDIO_14_4, - #endif - #ifdef CONFIG_RA_288_DECODER - BUF_AUDIO_28_8, - #endif - #ifdef CONFIG_MP3_DECODER - BUF_AUDIO_MPEG, - #endif - #ifdef CONFIG_ADPCM_MS_DECODER - BUF_AUDIO_MSADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_QT_DECODER - BUF_AUDIO_QTIMAADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_WAV_DECODER - BUF_AUDIO_MSIMAADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_DK3_DECODER - BUF_AUDIO_DK3ADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_DK4_DECODER - BUF_AUDIO_DK4ADPCM, - #endif - #ifdef CONFIG_ADPCM_IMA_WS_DECODER - BUF_AUDIO_VQA_IMA, - #endif - #ifdef CONFIG_ADPCM_IMA_SMJPEG_DECODER - BUF_AUDIO_SMJPEG_IMA, - #endif - #ifdef CONFIG_ADPCM_XA_DECODER - BUF_AUDIO_XA_ADPCM, - #endif - #ifdef CONFIG_ADPCM_4XM_DECODER - BUF_AUDIO_4X_ADPCM, - #endif - #ifdef CONFIG_ADPCM_EA_DECODER - BUF_AUDIO_EA_ADPCM, - #endif - #ifdef CONFIG_PCM_MULAW_DECODER - BUF_AUDIO_MULAW, - #endif - #ifdef CONFIG_PCM_ALAW_DECODER - BUF_AUDIO_ALAW, - #endif - #ifdef CONFIG_ROQ_DPCM_DECODER - BUF_AUDIO_ROQ, - #endif - #ifdef CONFIG_INTERPLAY_DPCM_DECODER - BUF_AUDIO_INTERPLAY, - #endif - #ifdef CONFIG_MACE3_DECODER - BUF_AUDIO_MAC3, - #endif - #ifdef CONFIG_MACE6_DECODER - BUF_AUDIO_MAC6, - #endif - #ifdef CONFIG_XAN_DPCM_DECODER - BUF_AUDIO_XAN_DPCM, - #endif - #ifdef CONFIG_VMDAUDIO_DECODER - BUF_AUDIO_VMD, - #endif - #ifdef CONFIG_FLAC_DECODER - BUF_AUDIO_FLAC, - #endif - #ifdef CONFIG_SHORTEN_DECODER - BUF_AUDIO_SHORTEN, - #endif - #ifdef CONFIG_ALAC_DECODER - BUF_AUDIO_ALAC, - #endif - #ifdef CONFIG_QDM2_DECODER - BUF_AUDIO_QDESIGN2, - #endif - #ifdef CONFIG_COOK_DECODER - BUF_AUDIO_COOK, - #endif - #ifdef CONFIG_TRUESPEECH_DECODER - BUF_AUDIO_TRUESPEECH, - #endif - #ifdef CONFIG_TTA_DECODER - BUF_AUDIO_TTA, - #endif - #ifdef CONFIG_SMACKAUDIO_DECODER - BUF_AUDIO_SMACKER, - #endif - #ifdef CONFIG_ADPCM_SWF_DECODER - BUF_AUDIO_FLVADPCM, - #endif - #ifdef CONFIG_WAVPACK_DECODER - BUF_AUDIO_WAVPACK, - #endif - - 0 -}; - -decoder_info_t dec_info_ffmpeg_audio = { - supported_audio_types, /* supported types */ - 6 /* priority */ -}; diff --git a/src/libffmpeg/ff_dvaudio_decoder.c b/src/libffmpeg/ff_dvaudio_decoder.c deleted file mode 100644 index 5106a402c..000000000 --- a/src/libffmpeg/ff_dvaudio_decoder.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (C) 2005 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * dv audio decoder based on patch by Dan Dennedy - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -#define LOG_MODULE "dvaudio" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "buffer.h" -#include "xineutils.h" - -#ifdef _MSC_VER -/* ffmpeg has own definitions of those types */ -# undef int8_t -# undef uint8_t -# undef int16_t -# undef uint16_t -# undef int32_t -# undef uint32_t -# undef int64_t -# undef uint64_t -#endif - -#ifdef HAVE_FFMPEG_AVUTIL_H -# include -#else -# include -#endif - -#include "libavcodec/dvdata.h" - -#ifdef _MSC_VER -# undef malloc -# undef free -# undef realloc -#endif - -#define AUDIOBUFSIZE 128*1024 -#define MAXFRAMESIZE 131072 - - -typedef struct { - audio_decoder_class_t decoder_class; -} dvaudio_class_t; - -typedef struct dvaudio_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int output_open; - int audio_channels; - int audio_bits; - int audio_sample_rate; - - unsigned char *buf; - int bufsize; - int size; - - char *decode_buffer; - int decoder_ok; - -} dvaudio_decoder_t; - - -/* - * This is the dumbest implementation of all -- it simply looks at - * a fixed offset and if pack isn't there -- fails. We might want - * to have a fallback mechanism for complete search of missing packs. - */ -static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) -{ - int offs; - - switch (t) { - case dv_audio_source: - offs = (80*6 + 80*16*3 + 3); - break; - case dv_audio_control: - offs = (80*6 + 80*16*4 + 3); - break; - case dv_video_control: - offs = (80*5 + 48 + 5); - break; - default: - return NULL; - } - - return (frame[offs] == t ? &frame[offs] : NULL); -} - -static inline uint16_t dv_audio_12to16(uint16_t sample) -{ - uint16_t shift, result; - - sample = (sample < 0x800) ? sample : sample | 0xf000; - shift = (sample & 0xf00) >> 8; - - if (shift < 0x2 || shift > 0xd) { - result = sample; - } else if (shift < 0x8) { - shift--; - result = (sample - (256 * shift)) << shift; - } else { - shift = 0xe - shift; - result = ((sample + ((256 * shift) + 1)) << shift) - 1; - } - - return result; -} - -/* - * There's a couple of assumptions being made here: - * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. - * We can pass them upwards when ffmpeg will be ready to deal with them. - * 2. We don't do software emphasis. - * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples - * are converted into 16bit linear ones. - */ -static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2) -{ - int size, i, j, d, of, smpls, freq, quant, half_ch; - uint16_t lc, rc; - const DVprofile* sys; - const uint8_t* as_pack; - - as_pack = dv_extract_pack(frame, dv_audio_source); - if (!as_pack) /* No audio ? */ - return 0; - - sys = dv_frame_profile(frame); - smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ - freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ - quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ - - if (quant > 1) - return -1; /* Unsupported quantization */ - - size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ - half_ch = sys->difseg_size/2; - - /* for each DIF segment */ - for (i = 0; i < sys->difseg_size; i++) { - frame += 6 * 80; /* skip DIF segment header */ - if (quant == 1 && i == half_ch) { - if (!pcm2) - break; - else - pcm = pcm2; - } - - for (j = 0; j < 9; j++) { - for (d = 8; d < 80; d += 2) { - if (quant == 0) { /* 16bit quantization */ - of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; - if (of*2 >= size) - continue; - -#ifdef WORDS_BIGENDIAN - pcm[of*2] = frame[d]; - pcm[of*2+1] = frame[d+1]; -#else - pcm[of*2] = frame[d+1]; - pcm[of*2+1] = frame[d]; -#endif - if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) - pcm[of*2+1] = 0; - } else { /* 12bit quantization */ - lc = ((uint16_t)frame[d] << 4) | - ((uint16_t)frame[d+2] >> 4); - rc = ((uint16_t)frame[d+1] << 4) | - ((uint16_t)frame[d+2] & 0x0f); - lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); - rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); - - of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; - if (of*2 >= size) - continue; - -#ifdef WORDS_BIGENDIAN - pcm[of*2] = lc >> 8; - pcm[of*2+1] = lc & 0xff; -#else - pcm[of*2] = lc & 0xff; - pcm[of*2+1] = lc >> 8; -#endif - of = sys->audio_shuffle[i%half_ch+half_ch][j] + - (d - 8)/3 * sys->audio_stride; -#ifdef WORDS_BIGENDIAN - pcm[of*2] = rc >> 8; - pcm[of*2+1] = rc & 0xff; -#else - pcm[of*2] = rc & 0xff; - pcm[of*2+1] = rc >> 8; -#endif - ++d; - } - } - - frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ - } - } - - return size; -} - -static void dvaudio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - int bytes_consumed; - int decode_buffer_size; - int offset; - int out; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - this->decode_buffer = xine_xmalloc(MAXFRAMESIZE); - - this->audio_sample_rate = buf->decoder_info[1]; - this->audio_bits = buf->decoder_info[2]; - this->audio_channels = buf->decoder_info[3]; - - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DV Audio"); - - this->decoder_ok = 1; - - return; - } - - if (this->decoder_ok && !(buf->decoder_flags & (BUF_FLAG_HEADER|BUF_FLAG_SPECIAL))) { - - if (!this->output_open) { - this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, - this->stream, this->audio_bits, this->audio_sample_rate, - _x_ao_channels2mode(this->audio_channels)); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("dvaudio: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - - offset = 0; - while (this->size>0) { - decode_buffer_size = dv_extract_audio(&this->buf[offset], this->decode_buffer, NULL); - - if (decode_buffer_size > -1) - bytes_consumed = dv_frame_profile(&this->buf[offset])->frame_size; - else - bytes_consumed = decode_buffer_size; - - /* dispatch the decoded audio */ - out = 0; - while (out < decode_buffer_size) { - audio_buffer = - this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "dvaudio: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if ((decode_buffer_size - out) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = decode_buffer_size - out; - - /* fill up this buffer */ - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - - out += bytes_to_send; - } - - this->size -= bytes_consumed; - offset += bytes_consumed; - } - - /* reset internal accumulation buffer */ - this->size = 0; - } - } -} - -static void dvaudio_reset (audio_decoder_t *this_gen) { - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - - this->size = 0; -} - -static void dvaudio_discontinuity (audio_decoder_t *this_gen) { -} - -static void dvaudio_dispose (audio_decoder_t *this_gen) { - - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free(this->buf); - free(this->decode_buffer); - - free (this_gen); -} - -static audio_decoder_t *dvaudio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - dvaudio_decoder_t *this ; - - this = (dvaudio_decoder_t *) xine_xmalloc (sizeof (dvaudio_decoder_t)); - - this->audio_decoder.decode_data = dvaudio_decode_data; - this->audio_decoder.reset = dvaudio_reset; - this->audio_decoder.discontinuity = dvaudio_discontinuity; - this->audio_decoder.dispose = dvaudio_dispose; - - this->output_open = 0; - this->audio_channels = 0; - this->stream = stream; - this->buf = NULL; - this->size = 0; - this->decoder_ok = 0; - - return &this->audio_decoder; -} - -static char *dvaudio_get_identifier (audio_decoder_class_t *this) { - return "dv audio"; -} - -static char *dvaudio_get_description (audio_decoder_class_t *this) { - return "dv audio decoder plugin"; -} - -static void dvaudio_dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_dvaudio_plugin (xine_t *xine, void *data) { - - dvaudio_class_t *this ; - - this = (dvaudio_class_t *) xine_xmalloc (sizeof (dvaudio_class_t)); - - this->decoder_class.open_plugin = dvaudio_open_plugin; - this->decoder_class.get_identifier = dvaudio_get_identifier; - this->decoder_class.get_description = dvaudio_get_description; - this->decoder_class.dispose = dvaudio_dispose_class; - - return this; -} - -static uint32_t supported_audio_types[] = { - BUF_AUDIO_DV, - 0 -}; - -static const decoder_info_t dec_info_dvaudio = { - supported_audio_types, /* supported types */ - 5 /* priority */ -}; - -/* - * exported plugin catalog entry - */ - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "dvaudio", XINE_VERSION_CODE, &dec_info_dvaudio, init_dvaudio_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libffmpeg/ff_mpeg_parser.c b/src/libffmpeg/ff_mpeg_parser.c deleted file mode 100644 index 70901d93b..000000000 --- a/src/libffmpeg/ff_mpeg_parser.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright (C) 2001-2004 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) - * based on libmpeg2 decoder. - */ -#define LOG_MODULE "mpeg_parser" -#define LOG_VERBOSE -/* -#define LOG -*/ -#include "ff_mpeg_parser.h" - -/* mpeg frame rate table from lavc */ -static const int frame_rate_tab[][2] = { - { 0, 0}, - {24000, 1001}, - { 24, 1}, - { 25, 1}, - {30000, 1001}, - { 30, 1}, - { 50, 1}, - {60000, 1001}, - { 60, 1}, - /* Xing's 15fps: (9) */ - { 15, 1}, - /* libmpeg3's "Unofficial economy rates": (10-13) */ - { 5, 1}, - { 10, 1}, - { 12, 1}, - { 15, 1}, - { 0, 0}, -}; - -void mpeg_parser_init (mpeg_parser_t *parser) -{ - parser->chunk_buffer = xine_xmalloc(BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); - mpeg_parser_reset(parser); -} - -void mpeg_parser_dispose (mpeg_parser_t *parser) -{ - if ( parser == NULL ) return; - - free(parser->chunk_buffer); -} - -void mpeg_parser_reset (mpeg_parser_t *parser) -{ - parser->shift = 0xffffff00; - parser->is_sequence_needed = 1; - parser->in_slice = 0; - parser->chunk_ptr = parser->chunk_buffer; - parser->chunk_start = parser->chunk_buffer; - parser->buffer_size = 0; - parser->code = 0xb4; - parser->picture_coding_type = 0; - parser->width = 0; - parser->height = 0; - parser->rate_code = 0; - parser->aspect_ratio_info = 0; - parser->frame_duration = 0; - parser->is_mpeg1 = 0; - parser->has_sequence = 0; - parser->frame_aspect_ratio = 0.0; -} - -static void parse_header_picture (mpeg_parser_t *parser, uint8_t * buffer) -{ - parser->picture_coding_type = (buffer [1] >> 3) & 7; -} - -static double get_aspect_ratio(mpeg_parser_t *parser) -{ - double ratio; - double mpeg1_pel_ratio[16] = {1.0 /* forbidden */, - 1.0, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, - 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 1.0 /*reserved*/ }; - - if( !parser->is_mpeg1 ) { - /* these hardcoded values are defined on mpeg2 standard for - * aspect ratio. other values are reserved or forbidden. */ - switch (parser->aspect_ratio_info) { - case 2: - ratio = 4.0 / 3.0; - break; - case 3: - ratio = 16.0 / 9.0; - break; - case 4: - ratio = 2.11 / 1.0; - break; - case 1: - default: - ratio = (double)parser->width / (double)parser->height; - break; - } - } else { - /* mpeg1 constants refer to pixel aspect ratio */ - ratio = (double)parser->width / (double)parser->height; - ratio /= mpeg1_pel_ratio[parser->aspect_ratio_info]; - } - - return ratio; -} - -static int parse_chunk (mpeg_parser_t *parser, int code, uint8_t *buffer, int len) -{ - int is_frame_done; - int next_code = parser->code; - - /* wait for sequence_header_code */ - if (parser->is_sequence_needed) { - if (code != 0xb3) { - lprintf("waiting for sequence header\n"); - parser->chunk_ptr = parser->chunk_buffer; - return 0; - } - } - - is_frame_done = parser->in_slice && ((!next_code) || (next_code == 0xb7)); - - if (is_frame_done) - parser->in_slice = 0; - - switch (code) { - case 0x00: /* picture_start_code */ - - parse_header_picture (parser, buffer); - - parser->in_slice = 1; - - switch (parser->picture_coding_type) { - case B_TYPE: - lprintf ("B-Frame\n"); - break; - - case P_TYPE: - lprintf ("P-Frame\n"); - break; - - case I_TYPE: - lprintf ("I-Frame\n"); - break; - } - break; - - case 0xb2: /* user data code */ - /* process_userdata(mpeg2dec, buffer); */ - break; - - case 0xb3: /* sequence_header_code */ - { - int value; - uint16_t width, height; - - if (parser->is_sequence_needed) { - parser->is_sequence_needed = 0; - } - - if ((buffer[6] & 0x20) != 0x20) { - lprintf("Invalid sequence: missing marker_bit\n"); - parser->has_sequence = 0; - break; /* missing marker_bit */ - } - - value = (buffer[0] << 16) | - (buffer[1] << 8) | - buffer[2]; - width = ((value >> 12) + 15) & ~15; - height = ((value & 0xfff) + 15) & ~15; - - if ((width > 1920) || (height > 1152)) { - lprintf("Invalid sequence: width=%d, height=%d\n", width, height); - parser->has_sequence = 0; - break; /* size restrictions for MP@HL */ - } - - parser->width = width; - parser->height = height; - parser->rate_code = buffer[3] & 15; - parser->aspect_ratio_info = buffer[3] >> 4; - - if (parser->rate_code < (sizeof(frame_rate_tab)/sizeof(*frame_rate_tab))) { - parser->frame_duration = 90000; - parser->frame_duration *= frame_rate_tab[parser->rate_code][1]; - parser->frame_duration /= frame_rate_tab[parser->rate_code][0]; - } else { - printf ("invalid/unknown frame rate code : %d \n", - parser->rate_code); - parser->frame_duration = 0; - } - - parser->has_sequence = 1; - parser->is_mpeg1 = 1; - } - break; - - case 0xb5: /* extension_start_code */ - switch (buffer[0] & 0xf0) { - case 0x10: /* sequence extension */ - parser->is_mpeg1 = 0; - } - - default: - if (code >= 0xb9) - lprintf ("stream not demultiplexed ?\n"); - - if (code >= 0xb0) - break; - } - return is_frame_done; -} - -static inline uint8_t *copy_chunk (mpeg_parser_t *parser, - uint8_t *current, uint8_t *end) -{ - uint32_t shift; - uint8_t *chunk_ptr; - uint8_t *limit; - uint8_t byte; - - shift = parser->shift; - chunk_ptr = parser->chunk_ptr; - - limit = current + (parser->chunk_buffer + BUFFER_SIZE - chunk_ptr); - if (limit > end) - limit = end; - - while (1) { - - byte = *current++; - *chunk_ptr++ = byte; - if (shift != 0x00000100) { - shift = (shift | byte) << 8; - if (current < limit) - continue; - if (current == end) { - parser->chunk_ptr = chunk_ptr; - parser->shift = shift; - lprintf("Need more bytes\n"); - return NULL; - } else { - /* we filled the chunk buffer without finding a start code */ - lprintf("Buffer full\n"); - parser->code = 0xb4; /* sequence_error_code */ - parser->chunk_ptr = parser->chunk_buffer; - return current; - } - } - lprintf("New chunk: 0x%2X\n", byte); - parser->chunk_ptr = chunk_ptr; - parser->shift = 0xffffff00; - parser->code = byte; - return current; - } -} - - -uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, - uint8_t *current, uint8_t *end, - int *flush) -{ - int ret; - uint8_t code; - - ret = 0; - *flush = 0; - - while (current != end) { - if (parser->chunk_ptr == parser->chunk_buffer) { - /* write the beginning of the chunk */ - parser->chunk_buffer[0] = 0x00; - parser->chunk_buffer[1] = 0x00; - parser->chunk_buffer[2] = 0x01; - parser->chunk_buffer[3] = parser->code; - parser->chunk_ptr += 4; - parser->chunk_start = parser->chunk_ptr; - parser->has_sequence = 0; - } - - code = parser->code; - - current = copy_chunk (parser, current, end); - if (current == NULL) - return NULL; - ret = parse_chunk (parser, code, parser->chunk_start, - parser->chunk_ptr - parser->chunk_start - 4); - parser->chunk_start = parser->chunk_ptr; - if (ret == 1) { - if (parser->has_sequence) { - parser->frame_aspect_ratio = get_aspect_ratio(parser); - } - parser->buffer_size = parser->chunk_ptr - parser->chunk_buffer - 4; - parser->chunk_ptr = parser->chunk_buffer; - - if (parser->code == 0xb7) /* sequence end, maybe a still menu */ - *flush = 1; - - return current; - } - } - - return NULL; -} diff --git a/src/libffmpeg/ff_mpeg_parser.h b/src/libffmpeg/ff_mpeg_parser.h deleted file mode 100644 index ea43a6ce4..000000000 --- a/src/libffmpeg/ff_mpeg_parser.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2001-2004 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * Simple MPEG-ES parser/framer by Thibaut Mattern (tmattern@noos.fr) - * based on libmpeg2 decoder. - */ -#ifndef HAVE_MPEG_PARSER_H -#define HAVE_MPEG_PARSER_H - -#include "xine_internal.h" -#include "ffmpeg_decoder.h" - -#define BUFFER_SIZE (1194 * 1024) /* libmpeg2's buffer size */ - -/* picture coding type (mpeg2 header) */ -#define I_TYPE 1 -#define P_TYPE 2 -#define B_TYPE 3 -#define D_TYPE 4 - -typedef struct mpeg_parser_s { - uint8_t *chunk_buffer; - uint8_t *chunk_ptr; - uint8_t *chunk_start; - uint32_t shift; - int buffer_size; - uint8_t code; - uint8_t picture_coding_type; - - uint8_t is_sequence_needed:1; - uint8_t is_mpeg1:1; /* public */ - uint8_t has_sequence:1; /* public */ - uint8_t in_slice:1; - - uint8_t rate_code:4; - - int aspect_ratio_info; - - /* public properties */ - uint16_t width; - uint16_t height; - int frame_duration; - double frame_aspect_ratio; - -} mpeg_parser_t; - -/* parser initialization */ -void mpeg_parser_init (mpeg_parser_t *parser); - -/* parser disposal */ -void mpeg_parser_dispose (mpeg_parser_t *parser); - -/* read a frame - * return a pointer to the first byte of the next frame - * or NULL if more bytes are needed - * *flush is set to 1 if the decoder must be flushed (needed for still menus) - */ -uint8_t *mpeg_parser_decode_data (mpeg_parser_t *parser, - uint8_t *current, uint8_t *end, - int *flush); - -/* reset the parser */ -void mpeg_parser_reset (mpeg_parser_t *parser); - -#endif /* HAVE_MPEG_PARSER_H */ diff --git a/src/libffmpeg/ff_video_decoder.c b/src/libffmpeg/ff_video_decoder.c deleted file mode 100644 index 3d9c0225a..000000000 --- a/src/libffmpeg/ff_video_decoder.c +++ /dev/null @@ -1,1889 +0,0 @@ -/* - * Copyright (C) 2001-2007 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * xine video decoder plugin using ffmpeg - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "ffmpeg_config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "ffmpeg_video_dec" -#define LOG_VERBOSE -/* -#define LOG -*/ -#include "xine_internal.h" -#include "bswap.h" -#include "buffer.h" -#include "xineutils.h" -#include "ffmpeg_decoder.h" -#include "ff_mpeg_parser.h" - -#ifdef HAVE_FFMPEG_AVUTIL_H -# include -#else -# include -#endif - -#define VIDEOBUFSIZE (128*1024) -#define SLICE_BUFFER_SIZE (1194*1024) - -#define SLICE_OFFSET_SIZE 128 - -#define ENABLE_DIRECT_RENDERING - -typedef struct ff_video_decoder_s ff_video_decoder_t; - -typedef struct ff_video_class_s { - video_decoder_class_t decoder_class; - - int pp_quality; - int thread_count; - int8_t skip_loop_filter_enum; - int8_t choose_speed_over_accuracy; - - xine_t *xine; -} ff_video_class_t; - -struct ff_video_decoder_s { - video_decoder_t video_decoder; - - ff_video_class_t *class; - - xine_stream_t *stream; - int64_t pts; - int video_step; - - uint8_t decoder_ok:1; - uint8_t decoder_init_mode:1; - uint8_t is_mpeg12:1; - uint8_t pp_available:1; - uint8_t yuv_init:1; - uint8_t is_direct_rendering_disabled:1; - uint8_t cs_convert_init:1; - uint8_t assume_bad_field_picture:1; - - xine_bmiheader bih; - unsigned char *buf; - int bufsize; - int size; - int skipframes; - - int slice_offset_size; - - AVFrame *av_frame; - AVCodecContext *context; - AVCodec *codec; - - int pp_quality; - int pp_flags; - pp_context_t *pp_context; - pp_mode_t *pp_mode; - - /* mpeg-es parsing */ - mpeg_parser_t *mpeg_parser; - - double aspect_ratio; - int aspect_ratio_prio; - int frame_flags; - int crop_right, crop_bottom; - - int output_format; - - xine_list_t *dr1_frames; - - yuv_planes_t yuv; - - AVPaletteControl palette_control; -}; - - -static void set_stream_info(ff_video_decoder_t *this) { - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->bih.biWidth); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->bih.biHeight); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO, this->aspect_ratio * 10000); -} - -#ifdef ENABLE_DIRECT_RENDERING -/* called from ffmpeg to do direct rendering method 1 */ -static int get_buffer(AVCodecContext *context, AVFrame *av_frame){ - ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; - vo_frame_t *img; - int width = context->width; - int height = context->height; - - if (!this->bih.biWidth || !this->bih.biHeight) { - this->bih.biWidth = width; - this->bih.biHeight = height; - - if (this->aspect_ratio_prio == 0) { - this->aspect_ratio = (double)width / (double)height; - this->aspect_ratio_prio = 1; - lprintf("default aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - } - - avcodec_align_dimensions(context, &width, &height); - - if( this->context->pix_fmt != PIX_FMT_YUV420P ) { - if (!this->is_direct_rendering_disabled) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n")); - this->is_direct_rendering_disabled = 1; - } - - /* FIXME: why should i have to do that ? */ - av_frame->data[0]= NULL; - av_frame->data[1]= NULL; - av_frame->data[2]= NULL; - return avcodec_default_get_buffer(context, av_frame); - } - - if((width != this->bih.biWidth) || (height != this->bih.biHeight)) { - if(this->stream->video_out->get_capabilities(this->stream->video_out) & VO_CAP_CROP) { - this->crop_right = width - this->bih.biWidth; - this->crop_bottom = height - this->bih.biHeight; - } else { - if (!this->is_direct_rendering_disabled) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n")); - this->is_direct_rendering_disabled = 1; - } - /* FIXME: why should i have to do that ? */ - av_frame->data[0]= NULL; - av_frame->data[1]= NULL; - av_frame->data[2]= NULL; - return avcodec_default_get_buffer(context, av_frame); - } - } - - img = this->stream->video_out->get_frame (this->stream->video_out, - width, - height, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - - av_frame->opaque = img; - - av_frame->data[0]= img->base[0]; - av_frame->data[1]= img->base[1]; - av_frame->data[2]= img->base[2]; - - av_frame->linesize[0] = img->pitches[0]; - av_frame->linesize[1] = img->pitches[1]; - av_frame->linesize[2] = img->pitches[2]; - - /* We should really keep track of the ages of xine frames (see - * avcodec_default_get_buffer in libavcodec/utils.c) - * For the moment tell ffmpeg that every frame is new (age = bignumber) */ - av_frame->age = 256*256*256*64; - - av_frame->type= FF_BUFFER_TYPE_USER; - - xine_list_push_back(this->dr1_frames, av_frame); - - return 0; -} - -static void release_buffer(struct AVCodecContext *context, AVFrame *av_frame){ - ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque; - - if (av_frame->type == FF_BUFFER_TYPE_USER) { - if ( av_frame->opaque ) { - vo_frame_t *img = (vo_frame_t *)av_frame->opaque; - - img->free(img); - } - - xine_list_iterator_t it; - - it = xine_list_find(this->dr1_frames, av_frame); - assert(it); - if( it != NULL ) - xine_list_remove(this->dr1_frames, it); - } else { - avcodec_default_release_buffer(context, av_frame); - } - - av_frame->opaque = NULL; - av_frame->data[0]= NULL; - av_frame->data[1]= NULL; - av_frame->data[2]= NULL; -} -#endif - -static const ff_codec_t ff_video_lookup[] = { - {BUF_VIDEO_MSMPEG4_V1, CODEC_ID_MSMPEG4V1, "Microsoft MPEG-4 v1 (ffmpeg)"}, - {BUF_VIDEO_MSMPEG4_V2, CODEC_ID_MSMPEG4V2, "Microsoft MPEG-4 v2 (ffmpeg)"}, - {BUF_VIDEO_MSMPEG4_V3, CODEC_ID_MSMPEG4V3, "Microsoft MPEG-4 v3 (ffmpeg)"}, - {BUF_VIDEO_WMV7, CODEC_ID_WMV1, "MS Windows Media Video 7 (ffmpeg)"}, - {BUF_VIDEO_WMV8, CODEC_ID_WMV2, "MS Windows Media Video 8 (ffmpeg)"}, - {BUF_VIDEO_WMV9, CODEC_ID_WMV3, "MS Windows Media Video 9 (ffmpeg)"}, - {BUF_VIDEO_VC1, CODEC_ID_VC1, "MS Windows Media Video VC-1 (ffmpeg)"}, - {BUF_VIDEO_MPEG4, CODEC_ID_MPEG4, "ISO MPEG-4 (ffmpeg)"}, - {BUF_VIDEO_XVID, CODEC_ID_MPEG4, "ISO MPEG-4 (XviD, ffmpeg)"}, - {BUF_VIDEO_DIVX5, CODEC_ID_MPEG4, "ISO MPEG-4 (DivX5, ffmpeg)"}, - {BUF_VIDEO_3IVX, CODEC_ID_MPEG4, "ISO MPEG-4 (3ivx, ffmpeg)"}, - {BUF_VIDEO_JPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, - {BUF_VIDEO_MJPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"}, - {BUF_VIDEO_MJPEG_B, CODEC_ID_MJPEGB, "Motion JPEG B (ffmpeg)"}, - {BUF_VIDEO_I263, CODEC_ID_H263I, "ITU H.263 (ffmpeg)"}, - {BUF_VIDEO_H263, CODEC_ID_H263, "H.263 (ffmpeg)"}, - {BUF_VIDEO_RV10, CODEC_ID_RV10, "Real Video 1.0 (ffmpeg)"}, - {BUF_VIDEO_RV20, CODEC_ID_RV20, "Real Video 2.0 (ffmpeg)"}, - {BUF_VIDEO_IV31, CODEC_ID_INDEO3, "Indeo Video 3.1 (ffmpeg)"}, - {BUF_VIDEO_IV32, CODEC_ID_INDEO3, "Indeo Video 3.2 (ffmpeg)"}, - {BUF_VIDEO_SORENSON_V1, CODEC_ID_SVQ1, "Sorenson Video 1 (ffmpeg)"}, - {BUF_VIDEO_SORENSON_V3, CODEC_ID_SVQ3, "Sorenson Video 3 (ffmpeg)"}, - {BUF_VIDEO_DV, CODEC_ID_DVVIDEO, "DV (ffmpeg)"}, - {BUF_VIDEO_HUFFYUV, CODEC_ID_HUFFYUV, "HuffYUV (ffmpeg)"}, - {BUF_VIDEO_VP31, CODEC_ID_VP3, "On2 VP3.1 (ffmpeg)"}, - {BUF_VIDEO_VP5, CODEC_ID_VP5, "On2 VP5 (ffmpeg)"}, - {BUF_VIDEO_VP6, CODEC_ID_VP6, "On2 VP6 (ffmpeg)"}, - {BUF_VIDEO_VP6F, CODEC_ID_VP6F, "On2 VP6 (ffmpeg)"}, - {BUF_VIDEO_4XM, CODEC_ID_4XM, "4X Video (ffmpeg)"}, - {BUF_VIDEO_CINEPAK, CODEC_ID_CINEPAK, "Cinepak (ffmpeg)"}, - {BUF_VIDEO_MSVC, CODEC_ID_MSVIDEO1, "Microsoft Video 1 (ffmpeg)"}, - {BUF_VIDEO_MSRLE, CODEC_ID_MSRLE, "Microsoft RLE (ffmpeg)"}, - {BUF_VIDEO_RPZA, CODEC_ID_RPZA, "Apple Quicktime Video/RPZA (ffmpeg)"}, - {BUF_VIDEO_CYUV, CODEC_ID_CYUV, "Creative YUV (ffmpeg)"}, - {BUF_VIDEO_ROQ, CODEC_ID_ROQ, "Id Software RoQ (ffmpeg)"}, - {BUF_VIDEO_IDCIN, CODEC_ID_IDCIN, "Id Software CIN (ffmpeg)"}, - {BUF_VIDEO_WC3, CODEC_ID_XAN_WC3, "Xan (ffmpeg)"}, - {BUF_VIDEO_VQA, CODEC_ID_WS_VQA, "Westwood Studios VQA (ffmpeg)"}, - {BUF_VIDEO_INTERPLAY, CODEC_ID_INTERPLAY_VIDEO, "Interplay MVE (ffmpeg)"}, - {BUF_VIDEO_FLI, CODEC_ID_FLIC, "FLIC Video (ffmpeg)"}, - {BUF_VIDEO_8BPS, CODEC_ID_8BPS, "Planar RGB (ffmpeg)"}, - {BUF_VIDEO_SMC, CODEC_ID_SMC, "Apple Quicktime Graphics/SMC (ffmpeg)"}, - {BUF_VIDEO_DUCKTM1, CODEC_ID_TRUEMOTION1,"Duck TrueMotion v1 (ffmpeg)"}, - {BUF_VIDEO_DUCKTM2, CODEC_ID_TRUEMOTION2,"Duck TrueMotion v2 (ffmpeg)"}, - {BUF_VIDEO_VMD, CODEC_ID_VMDVIDEO, "Sierra VMD Video (ffmpeg)"}, - {BUF_VIDEO_ZLIB, CODEC_ID_ZLIB, "ZLIB Video (ffmpeg)"}, - {BUF_VIDEO_MSZH, CODEC_ID_MSZH, "MSZH Video (ffmpeg)"}, - {BUF_VIDEO_ASV1, CODEC_ID_ASV1, "ASV v1 Video (ffmpeg)"}, - {BUF_VIDEO_ASV2, CODEC_ID_ASV2, "ASV v2 Video (ffmpeg)"}, - {BUF_VIDEO_ATIVCR1, CODEC_ID_VCR1, "ATI VCR-1 (ffmpeg)"}, - {BUF_VIDEO_FLV1, CODEC_ID_FLV1, "Flash Video (ffmpeg)"}, - {BUF_VIDEO_QTRLE, CODEC_ID_QTRLE, "Apple Quicktime Animation/RLE (ffmpeg)"}, - {BUF_VIDEO_H264, CODEC_ID_H264, "H.264/AVC (ffmpeg)"}, - {BUF_VIDEO_H261, CODEC_ID_H261, "H.261 (ffmpeg)"}, - {BUF_VIDEO_AASC, CODEC_ID_AASC, "Autodesk Video (ffmpeg)"}, - {BUF_VIDEO_LOCO, CODEC_ID_LOCO, "LOCO (ffmpeg)"}, - {BUF_VIDEO_QDRW, CODEC_ID_QDRAW, "QuickDraw (ffmpeg)"}, - {BUF_VIDEO_QPEG, CODEC_ID_QPEG, "Q-Team QPEG (ffmpeg)"}, - {BUF_VIDEO_TSCC, CODEC_ID_TSCC, "TechSmith Video (ffmpeg)"}, - {BUF_VIDEO_ULTI, CODEC_ID_ULTI, "IBM UltiMotion (ffmpeg)"}, - {BUF_VIDEO_WNV1, CODEC_ID_WNV1, "Winnow Video (ffmpeg)"}, - {BUF_VIDEO_XL, CODEC_ID_VIXL, "Miro/Pinnacle VideoXL (ffmpeg)"}, - {BUF_VIDEO_RT21, CODEC_ID_INDEO2, "Indeo/RealTime 2 (ffmpeg)"}, - {BUF_VIDEO_FPS1, CODEC_ID_FRAPS, "Fraps (ffmpeg)"}, - {BUF_VIDEO_MPEG, CODEC_ID_MPEG1VIDEO, "MPEG 1/2 (ffmpeg)"}, - {BUF_VIDEO_CSCD, CODEC_ID_CSCD, "CamStudio (ffmpeg)"}, - {BUF_VIDEO_AVS, CODEC_ID_AVS, "AVS (ffmpeg)"}, - {BUF_VIDEO_ALGMM, CODEC_ID_MMVIDEO, "American Laser Games MM (ffmpeg)"}, - {BUF_VIDEO_ZMBV, CODEC_ID_ZMBV, "Zip Motion Blocks Video (ffmpeg)"}, - {BUF_VIDEO_SMACKER, CODEC_ID_SMACKVIDEO, "Smacker (ffmpeg)"}, - {BUF_VIDEO_NUV, CODEC_ID_NUV, "NuppelVideo (ffmpeg)"}, - {BUF_VIDEO_KMVC, CODEC_ID_KMVC, "Karl Morton's Video Codec (ffmpeg)"}, - {BUF_VIDEO_FLASHSV, CODEC_ID_FLASHSV, "Flash Screen Video (ffmpeg)"}, - {BUF_VIDEO_CAVS, CODEC_ID_CAVS, "Chinese AVS (ffmpeg)"}, - {BUF_VIDEO_VMNC, CODEC_ID_VMNC, "VMware Screen Codec (ffmpeg)"}, - {BUF_VIDEO_THEORA_RAW, CODEC_ID_THEORA, "Theora (ffmpeg)"}, -}; - -static const char *const skip_loop_filter_enum_names[] = { - "default", /* AVDISCARD_DEFAULT */ - "none", /* AVDISCARD_NONE */ - "nonref", /* AVDISCARD_NONREF */ - "bidir", /* AVDISCARD_BIDIR */ - "nonkey", /* AVDISCARD_NONKEY */ - "all", /* AVDISCARD_ALL */ - NULL -}; - -static const int skip_loop_filter_enum_values[] = { - AVDISCARD_DEFAULT, - AVDISCARD_NONE, - AVDISCARD_NONREF, - AVDISCARD_BIDIR, - AVDISCARD_NONKEY, - AVDISCARD_ALL -}; - -static void init_video_codec (ff_video_decoder_t *this, unsigned int codec_type) { - size_t i; - - /* find the decoder */ - this->codec = NULL; - - for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++) - if(ff_video_lookup[i].type == codec_type) { - pthread_mutex_lock(&ffmpeg_lock); - this->codec = avcodec_find_decoder(ff_video_lookup[i].id); - pthread_mutex_unlock(&ffmpeg_lock); - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, - ff_video_lookup[i].name); - break; - } - - if (!this->codec) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), - codec_type); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); - return; - } - - lprintf("lavc decoder found\n"); - - /* force (width % 8 == 0), otherwise there will be - * display problems with Xv. - */ - this->bih.biWidth = (this->bih.biWidth + 1) & (~1); - - this->context->width = this->bih.biWidth; - this->context->height = this->bih.biHeight; - this->context->stream_codec_tag = this->context->codec_tag = - _x_stream_info_get(this->stream, XINE_STREAM_INFO_VIDEO_FOURCC); - - - /* Some codecs (eg rv10) copy flags in init so it's necessary to set - * this flag here in case we are going to use direct rendering */ - if(this->codec->capabilities & CODEC_CAP_DR1) { - this->context->flags |= CODEC_FLAG_EMU_EDGE; - } - - if (this->class->choose_speed_over_accuracy) - this->context->flags2 |= CODEC_FLAG2_FAST; - - pthread_mutex_lock(&ffmpeg_lock); - if (avcodec_open (this->context, this->codec) < 0) { - pthread_mutex_unlock(&ffmpeg_lock); - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: couldn't open decoder\n")); - free(this->context); - this->context = NULL; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); - return; - } - - if (this->class->thread_count > 1) { - avcodec_thread_init(this->context, this->class->thread_count); - this->context->thread_count = this->class->thread_count; - } - - this->context->skip_loop_filter = skip_loop_filter_enum_values[this->class->skip_loop_filter_enum]; - - pthread_mutex_unlock(&ffmpeg_lock); - - lprintf("lavc decoder opened\n"); - - this->decoder_ok = 1; - - if ((codec_type != BUF_VIDEO_MPEG) && - (codec_type != BUF_VIDEO_DV)) { - - if (!this->bih.biWidth || !this->bih.biHeight) { - this->bih.biWidth = this->context->width; - this->bih.biHeight = this->context->height; - } - - - set_stream_info(this); - } - - (this->stream->video_out->open) (this->stream->video_out, this->stream); - - this->skipframes = 0; - - /* enable direct rendering by default */ - this->output_format = XINE_IMGFMT_YV12; -#ifdef ENABLE_DIRECT_RENDERING - if( this->codec->capabilities & CODEC_CAP_DR1 && this->codec->id != CODEC_ID_H264 ) { - this->context->get_buffer = get_buffer; - this->context->release_buffer = release_buffer; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: direct rendering enabled\n")); - } -#endif - - /* flag for interlaced streams */ - this->frame_flags = 0; - /* FIXME: which codecs can be interlaced? - FIXME: check interlaced DCT and other codec specific info. */ - switch( codec_type ) { - case BUF_VIDEO_DV: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_MPEG: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_MJPEG: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_HUFFYUV: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - case BUF_VIDEO_H264: - this->frame_flags |= VO_INTERLACED_FLAG; - break; - } - -} - -static void choose_speed_over_accuracy_cb(void *user_data, xine_cfg_entry_t *entry) { - ff_video_class_t *class = (ff_video_class_t *) user_data; - - class->choose_speed_over_accuracy = entry->num_value; -} - -static void skip_loop_filter_enum_cb(void *user_data, xine_cfg_entry_t *entry) { - ff_video_class_t *class = (ff_video_class_t *) user_data; - - class->skip_loop_filter_enum = entry->num_value; -} - -static void thread_count_cb(void *user_data, xine_cfg_entry_t *entry) { - ff_video_class_t *class = (ff_video_class_t *) user_data; - - class->thread_count = entry->num_value; -} - -static void pp_quality_cb(void *user_data, xine_cfg_entry_t *entry) { - ff_video_class_t *class = (ff_video_class_t *) user_data; - - class->pp_quality = entry->num_value; -} - -static void pp_change_quality (ff_video_decoder_t *this) { - this->pp_quality = this->class->pp_quality; - - if(this->pp_available && this->pp_quality) { - if(!this->pp_context && this->context) - this->pp_context = pp_get_context(this->context->width, this->context->height, - this->pp_flags); - if(this->pp_mode) - pp_free_mode(this->pp_mode); - - this->pp_mode = pp_get_mode_by_name_and_quality("hb:a,vb:a,dr:a", - this->pp_quality); - } else { - if(this->pp_mode) { - pp_free_mode(this->pp_mode); - this->pp_mode = NULL; - } - - if(this->pp_context) { - pp_free_context(this->pp_context); - this->pp_context = NULL; - } - } -} - -static void init_postprocess (ff_video_decoder_t *this) { - uint32_t cpu_caps; - - /* Allow post processing on mpeg-4 (based) codecs */ - switch(this->codec->id) { - case CODEC_ID_MPEG4: - case CODEC_ID_MSMPEG4V1: - case CODEC_ID_MSMPEG4V2: - case CODEC_ID_MSMPEG4V3: - case CODEC_ID_WMV1: - case CODEC_ID_WMV2: - this->pp_available = 1; - break; - default: - this->pp_available = 0; - break; - } - - /* Detect what cpu accel we have */ - cpu_caps = xine_mm_accel(); - this->pp_flags = PP_FORMAT_420; - - if(cpu_caps & MM_ACCEL_X86_MMX) - this->pp_flags |= PP_CPU_CAPS_MMX; - - if(cpu_caps & MM_ACCEL_X86_MMXEXT) - this->pp_flags |= PP_CPU_CAPS_MMX2; - - if(cpu_caps & MM_ACCEL_X86_3DNOW) - this->pp_flags |= PP_CPU_CAPS_3DNOW; - - /* Set level */ - pp_change_quality(this); -} - -static int ff_handle_mpeg_sequence(ff_video_decoder_t *this, mpeg_parser_t *parser) { - - /* - * init codec - */ - if (this->decoder_init_mode) { - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, - "mpeg-1 (ffmpeg)"); - - init_video_codec (this, BUF_VIDEO_MPEG); - this->decoder_init_mode = 0; - } - - /* frame format change */ - if ((parser->width != this->bih.biWidth) || - (parser->height != this->bih.biHeight) || - (parser->frame_aspect_ratio != this->aspect_ratio)) { - xine_event_t event; - xine_format_change_data_t data; - - this->bih.biWidth = parser->width; - this->bih.biHeight = parser->height; - this->aspect_ratio = parser->frame_aspect_ratio; - this->aspect_ratio_prio = 2; - lprintf("mpeg seq aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - - event.type = XINE_EVENT_FRAME_FORMAT_CHANGE; - event.stream = this->stream; - event.data = &data; - event.data_length = sizeof(data); - data.width = this->bih.biWidth; - data.height = this->bih.biHeight; - data.aspect = this->aspect_ratio; - data.pan_scan = 0; - xine_event_send(this->stream, &event); - } - this->video_step = this->mpeg_parser->frame_duration; - - return 1; -} - -static void ff_convert_frame(ff_video_decoder_t *this, vo_frame_t *img) { - int y; - uint8_t *dy, *du, *dv, *sy, *su, *sv; - - dy = img->base[0]; - du = img->base[1]; - dv = img->base[2]; - sy = this->av_frame->data[0]; - su = this->av_frame->data[1]; - sv = this->av_frame->data[2]; - - if (this->context->pix_fmt == PIX_FMT_YUV410P) { - - yuv9_to_yv12( - /* Y */ - this->av_frame->data[0], - this->av_frame->linesize[0], - img->base[0], - img->pitches[0], - /* U */ - this->av_frame->data[1], - this->av_frame->linesize[1], - img->base[1], - img->pitches[1], - /* V */ - this->av_frame->data[2], - this->av_frame->linesize[2], - img->base[2], - img->pitches[2], - /* width x height */ - img->width, - img->height); - - } else if (this->context->pix_fmt == PIX_FMT_YUV411P) { - - yuv411_to_yv12( - /* Y */ - this->av_frame->data[0], - this->av_frame->linesize[0], - img->base[0], - img->pitches[0], - /* U */ - this->av_frame->data[1], - this->av_frame->linesize[1], - img->base[1], - img->pitches[1], - /* V */ - this->av_frame->data[2], - this->av_frame->linesize[2], - img->base[2], - img->pitches[2], - /* width x height */ - img->width, - img->height); - - } else if (this->context->pix_fmt == PIX_FMT_RGBA32) { - - int x, plane_ptr = 0; - uint32_t *argb_pixels; - uint32_t argb; - - for(y = 0; y < img->height; y++) { - argb_pixels = (uint32_t *)sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - /* this is endian-safe as the ARGB pixels are stored in - * machine order */ - argb = *argb_pixels++; - r = (argb >> 16) & 0xFF; - g = (argb >> 8) & 0xFF; - b = (argb >> 0) & 0xFF; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_RGB565) { - - int x, plane_ptr = 0; - uint8_t *src; - uint16_t pixel16; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - /* a 16-bit RGB565 pixel is supposed to be stored in native-endian - * byte order; the following should be endian-safe */ - pixel16 = *((uint16_t *)src); - src += 2; - b = (pixel16 << 3) & 0xFF; - g = (pixel16 >> 3) & 0xFF; - r = (pixel16 >> 8) & 0xFF; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_RGB555) { - - int x, plane_ptr = 0; - uint8_t *src; - uint16_t pixel16; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - /* a 16-bit RGB555 pixel is supposed to be stored in native-endian - * byte order; the following should be endian-safe */ - pixel16 = *((uint16_t *)src); - src += 2; - b = (pixel16 << 3) & 0xFF; - g = (pixel16 >> 2) & 0xFF; - r = (pixel16 >> 7) & 0xFF; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_BGR24) { - - int x, plane_ptr = 0; - uint8_t *src; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - b = *src++; - g = *src++; - r = *src++; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_RGB24) { - - int x, plane_ptr = 0; - uint8_t *src; - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - uint8_t r, g, b; - - r = *src++; - g = *src++; - b = *src++; - - this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b); - this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b); - this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b); - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else if (this->context->pix_fmt == PIX_FMT_PAL8) { - - int x, plane_ptr = 0; - uint8_t *src; - uint8_t pixel; - uint32_t *palette32 = (uint32_t *)su; /* palette is in data[1] */ - uint32_t rgb_color; - uint8_t r, g, b; - uint8_t y_palette[256]; - uint8_t u_palette[256]; - uint8_t v_palette[256]; - - for (x = 0; x < 256; x++) { - rgb_color = palette32[x]; - b = rgb_color & 0xFF; - rgb_color >>= 8; - g = rgb_color & 0xFF; - rgb_color >>= 8; - r = rgb_color & 0xFF; - y_palette[x] = COMPUTE_Y(r, g, b); - u_palette[x] = COMPUTE_U(r, g, b); - v_palette[x] = COMPUTE_V(r, g, b); - } - - for(y = 0; y < img->height; y++) { - src = sy; - for(x = 0; x < img->width; x++) { - pixel = *src++; - - this->yuv.y[plane_ptr] = y_palette[pixel]; - this->yuv.u[plane_ptr] = u_palette[pixel]; - this->yuv.v[plane_ptr] = v_palette[pixel]; - plane_ptr++; - } - sy += this->av_frame->linesize[0]; - } - - yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]); - - } else { - - for (y=0; yheight; y++) { - xine_fast_memcpy (dy, sy, img->width); - - dy += img->pitches[0]; - - sy += this->av_frame->linesize[0]; - } - - for (y=0; y<(img->height/2); y++) { - - if (this->context->pix_fmt != PIX_FMT_YUV444P) { - - xine_fast_memcpy (du, su, img->width/2); - xine_fast_memcpy (dv, sv, img->width/2); - - } else { - - int x; - uint8_t *src; - uint8_t *dst; - - /* subsample */ - - src = su; dst = du; - for (x=0; x<(img->width/2); x++) { - *dst = *src; - dst++; - src += 2; - } - src = sv; dst = dv; - for (x=0; x<(img->width/2); x++) { - *dst = *src; - dst++; - src += 2; - } - - } - - du += img->pitches[1]; - dv += img->pitches[2]; - - if (this->context->pix_fmt != PIX_FMT_YUV420P) { - su += 2*this->av_frame->linesize[1]; - sv += 2*this->av_frame->linesize[2]; - } else { - su += this->av_frame->linesize[1]; - sv += this->av_frame->linesize[2]; - } - } - } -} - -static void ff_check_bufsize (ff_video_decoder_t *this, int size) { - if (size > this->bufsize) { - this->bufsize = size + size / 2; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc(this->buf, this->bufsize + FF_INPUT_BUFFER_PADDING_SIZE ); - } -} - -static void ff_handle_preview_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - int codec_type; - - lprintf ("preview buffer\n"); - - codec_type = buf->type & 0xFFFF0000; - if (codec_type == BUF_VIDEO_MPEG) { - this->is_mpeg12 = 1; - if ( this->mpeg_parser == NULL ) { - this->mpeg_parser = xine_xmalloc(sizeof(mpeg_parser_t)); - mpeg_parser_init(this->mpeg_parser); - this->decoder_init_mode = 0; - } - } - - if (this->decoder_init_mode && !this->is_mpeg12) { - init_video_codec(this, codec_type); - init_postprocess(this); - this->decoder_init_mode = 0; - } -} - -static void ff_handle_header_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - - lprintf ("header buffer\n"); - - /* accumulate data */ - ff_check_bufsize(this, this->size + buf->size); - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - int codec_type; - - lprintf ("header complete\n"); - codec_type = buf->type & 0xFFFF0000; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - - lprintf("standard header\n"); - - /* init package containing bih */ - memcpy ( &this->bih, this->buf, sizeof(xine_bmiheader) ); - - if (this->bih.biSize > sizeof(xine_bmiheader)) { - this->context->extradata_size = this->bih.biSize - sizeof(xine_bmiheader); - this->context->extradata = malloc(this->context->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, this->buf + sizeof(xine_bmiheader), - this->context->extradata_size); - } - - this->context->bits_per_sample = this->bih.biBitCount; - - } else { - - switch (codec_type) { - case BUF_VIDEO_RV10: - case BUF_VIDEO_RV20: - this->bih.biWidth = _X_BE_16(&this->buf[12]); - this->bih.biHeight = _X_BE_16(&this->buf[14]); - - this->context->sub_id = _X_BE_32(&this->buf[30]); - - this->context->slice_offset = xine_xmalloc(sizeof(int)*SLICE_OFFSET_SIZE); - this->slice_offset_size = SLICE_OFFSET_SIZE; - - lprintf("w=%d, h=%d\n", this->bih.biWidth, this->bih.biHeight); - - break; - default: - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_video_dec: unknown header for buf type 0x%X\n", codec_type); - return; - } - } - - /* reset accumulator */ - this->size = 0; - } -} - -static void ff_handle_special_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - /* take care of all the various types of special buffers - * note that order is important here */ - lprintf("special buffer\n"); - - if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM && - !this->context->extradata_size) { - - lprintf("BUF_SPECIAL_STSD_ATOM\n"); - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = xine_xmalloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); - - } else if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG && - !this->context->extradata_size) { - - lprintf("BUF_SPECIAL_DECODER_CONFIG\n"); - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = xine_xmalloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); - - } else if (buf->decoder_info[1] == BUF_SPECIAL_PALETTE) { - unsigned int i; - - palette_entry_t *demuxer_palette; - AVPaletteControl *decoder_palette; - - lprintf("BUF_SPECIAL_PALETTE\n"); - this->context->palctrl = &this->palette_control; - decoder_palette = (AVPaletteControl *)this->context->palctrl; - demuxer_palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - - for (i = 0; i < buf->decoder_info[2]; i++) { - decoder_palette->palette[i] = - (demuxer_palette[i].r << 16) | - (demuxer_palette[i].g << 8) | - (demuxer_palette[i].b << 0); - } - decoder_palette->palette_changed = 1; - - } else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) { - int i; - - lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n"); - this->context->slice_count = buf->decoder_info[2]+1; - - lprintf("slice_count=%d\n", this->context->slice_count); - - if(this->context->slice_count > this->slice_offset_size) { - this->context->slice_offset = realloc(this->context->slice_offset, - sizeof(int)*this->context->slice_count); - this->slice_offset_size = this->context->slice_count; - } - - for(i = 0; i < this->context->slice_count; i++) { - this->context->slice_offset[i] = - ((uint32_t *) buf->decoder_info_ptr[2])[(2*i)+1]; - lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]); - } - } -} - -static void ff_handle_mpeg12_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - - vo_frame_t *img; - int free_img; - int got_picture, len; - int offset = 0; - int flush = 0; - int size = buf->size; - - lprintf("handle_mpeg12_buffer\n"); - - while ((size > 0) || (flush == 1)) { - - uint8_t *current; - int next_flush; - - got_picture = 0; - if (!flush) { - current = mpeg_parser_decode_data(this->mpeg_parser, - buf->content + offset, buf->content + offset + size, - &next_flush); - } else { - current = buf->content + offset + size; /* end of the buffer */ - next_flush = 0; - } - if (current == NULL) { - lprintf("current == NULL\n"); - return; - } - - if (this->mpeg_parser->has_sequence) { - ff_handle_mpeg_sequence(this, this->mpeg_parser); - } - - if (!this->decoder_ok) - return; - - if (flush) { - lprintf("flush lavc buffers\n"); - /* hack: ffmpeg outputs the last frame if size=0 */ - this->mpeg_parser->buffer_size = 0; - } - - /* skip decoding b frames if too late */ - this->context->hurry_up = (this->skipframes > 0); - - lprintf("avcodec_decode_video: size=%d\n", this->mpeg_parser->buffer_size); - len = avcodec_decode_video (this->context, this->av_frame, - &got_picture, this->mpeg_parser->chunk_buffer, - this->mpeg_parser->buffer_size); - lprintf("avcodec_decode_video: decoded_size=%d, got_picture=%d\n", - len, got_picture); - len = current - buf->content - offset; - lprintf("avcodec_decode_video: consumed_size=%d\n", len); - - flush = next_flush; - - if ((len < 0) || (len > buf->size)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_video_dec: error decompressing frame\n"); - size = 0; /* draw a bad frame and exit */ - } else { - size -= len; - offset += len; - } - - if (got_picture && this->av_frame->data[0]) { - /* got a picture, draw it */ - if(!this->av_frame->opaque) { - /* indirect rendering */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->bih.biWidth, - this->bih.biHeight, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - free_img = 1; - } else { - /* DR1 */ - img = (vo_frame_t*) this->av_frame->opaque; - free_img = 0; - } - - img->pts = this->pts; - this->pts = 0; - - if (this->av_frame->repeat_pict) - img->duration = this->video_step * 3 / 2; - else - img->duration = this->video_step; - - img->crop_right = this->crop_right; - img->crop_bottom = this->crop_bottom; - - this->skipframes = img->draw(img, this->stream); - - if(free_img) - img->free(img); - - } else { - - if (this->context->hurry_up) { - /* skipped frame, output a bad frame */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->bih.biWidth, - this->bih.biHeight, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - img->pts = 0; - img->duration = this->video_step; - img->bad_frame = 1; - this->skipframes = img->draw(img, this->stream); - img->free(img); - } - } - } -} - -static void ff_handle_buffer (ff_video_decoder_t *this, buf_element_t *buf) { - uint8_t *chunk_buf = this->buf; - AVRational avr00 = {0, 1}; - - lprintf("handle_buffer\n"); - - if (!this->decoder_ok) { - if (this->decoder_init_mode) { - int codec_type = buf->type & 0xFFFF0000; - - /* init ffmpeg decoder */ - init_video_codec(this, codec_type); - init_postprocess(this); - this->decoder_init_mode = 0; - } else { - return; - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAME_START) { - lprintf("BUF_FLAG_FRAME_START\n"); - this->size = 0; - } - - /* data accumulation */ - if (buf->size > 0) { - if ((this->size == 0) && - ((buf->size + FF_INPUT_BUFFER_PADDING_SIZE) < buf->max_size) && - (buf->decoder_flags & BUF_FLAG_FRAME_END)) { - /* buf contains a complete frame */ - /* no memcpy needed */ - chunk_buf = buf->content; - this->size = buf->size; - lprintf("no memcpy needed to accumulate data\n"); - } else { - /* copy data into our internal buffer */ - ff_check_bufsize(this, this->size + buf->size); - chunk_buf = this->buf; /* ff_check_bufsize might realloc this->buf */ - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - lprintf("accumulate data into this->buf\n"); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - vo_frame_t *img; - int free_img; - int got_picture, len; - int got_one_picture = 0; - int offset = 0; - int codec_type = buf->type & 0xFFFF0000; - int video_step_to_use = this->video_step; - - /* pad input data */ - /* note: bitstream, alt bitstream reader or something will cause - * severe mpeg4 artifacts if padding is less than 32 bits. - */ - memset(&chunk_buf[this->size], 0, FF_INPUT_BUFFER_PADDING_SIZE); - - while (this->size > 0) { - - /* DV frames can be completely skipped */ - if( codec_type == BUF_VIDEO_DV && this->skipframes ) { - this->size = 0; - got_picture = 0; - } else { - /* skip decoding b frames if too late */ - this->context->hurry_up = (this->skipframes > 0); - - lprintf("buffer size: %d\n", this->size); - len = avcodec_decode_video (this->context, this->av_frame, - &got_picture, &chunk_buf[offset], - this->size); - lprintf("consumed size: %d, got_picture: %d\n", len, got_picture); - if ((len <= 0) || (len > this->size)) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "ffmpeg_video_dec: error decompressing frame\n"); - this->size = 0; - - } else { - - offset += len; - this->size -= len; - - if (this->size > 0) { - ff_check_bufsize(this, this->size); - memmove (this->buf, &chunk_buf[offset], this->size); - chunk_buf = this->buf; - } - } - } - - /* use externally provided video_step or fall back to stream's time_base otherwise */ - video_step_to_use = (this->video_step || !this->context->time_base.den) ? this->video_step : (int)(90000ll * this->context->time_base.num / this->context->time_base.den); - - /* aspect ratio provided by ffmpeg, override previous setting */ - if ((this->aspect_ratio_prio < 2) && - av_cmp_q(this->context->sample_aspect_ratio, avr00)) { - - if (!this->bih.biWidth || !this->bih.biHeight) { - this->bih.biWidth = this->context->width; - this->bih.biHeight = this->context->height; - } - - this->aspect_ratio = av_q2d(this->context->sample_aspect_ratio) * - (double)this->bih.biWidth / (double)this->bih.biHeight; - this->aspect_ratio_prio = 2; - lprintf("ffmpeg aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - - if (got_picture && this->av_frame->data[0]) { - /* got a picture, draw it */ - got_one_picture = 1; - if(!this->av_frame->opaque) { - /* indirect rendering */ - - /* initialize the colorspace converter */ - if (!this->cs_convert_init) { - if ((this->context->pix_fmt == PIX_FMT_RGBA32) || - (this->context->pix_fmt == PIX_FMT_RGB565) || - (this->context->pix_fmt == PIX_FMT_RGB555) || - (this->context->pix_fmt == PIX_FMT_BGR24) || - (this->context->pix_fmt == PIX_FMT_RGB24) || - (this->context->pix_fmt == PIX_FMT_PAL8)) { - this->output_format = XINE_IMGFMT_YUY2; - init_yuv_planes(&this->yuv, this->bih.biWidth, this->bih.biHeight); - this->yuv_init = 1; - } - this->cs_convert_init = 1; - } - - if (this->aspect_ratio_prio == 0) { - this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight; - this->aspect_ratio_prio = 1; - lprintf("default aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - - /* xine-lib expects the framesize to be a multiple of 16x16 (macroblock) */ - img = this->stream->video_out->get_frame (this->stream->video_out, - (this->bih.biWidth + 15) & ~15, - (this->bih.biHeight + 15) & ~15, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - free_img = 1; - } else { - /* DR1 */ - img = (vo_frame_t*) this->av_frame->opaque; - free_img = 0; - } - - /* post processing */ - if(this->pp_quality != this->class->pp_quality) - pp_change_quality(this); - - if(this->pp_available && this->pp_quality) { - - if(this->av_frame->opaque) { - /* DR1 */ - img = this->stream->video_out->get_frame (this->stream->video_out, - (img->width + 15) & ~15, - (img->height + 15) & ~15, - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - free_img = 1; - } - - pp_postprocess(this->av_frame->data, this->av_frame->linesize, - img->base, img->pitches, - img->width, img->height, - this->av_frame->qscale_table, this->av_frame->qstride, - this->pp_mode, this->pp_context, - this->av_frame->pict_type); - - } else if (!this->av_frame->opaque) { - /* colorspace conversion or copy */ - ff_convert_frame(this, img); - } - - img->pts = this->pts; - this->pts = 0; - - /* workaround for weird 120fps streams */ - if( video_step_to_use == 750 ) { - /* fallback to the VIDEO_PTS_MODE */ - video_step_to_use = 0; - } - - if (this->av_frame->repeat_pict) - img->duration = video_step_to_use * 3 / 2; - else - img->duration = video_step_to_use; - - /* additionally crop away the extra pixels due to adjusting frame size above */ - img->crop_right = this->crop_right + (img->width - this->bih.biWidth); - img->crop_bottom = this->crop_bottom + (img->height - this->bih.biHeight); - - /* transfer some more frame settings for deinterlacing */ - img->progressive_frame = !this->av_frame->interlaced_frame; - img->top_field_first = this->av_frame->top_field_first; - - this->skipframes = img->draw(img, this->stream); - - if(free_img) - img->free(img); - } - } - - /* workaround for demux_mpeg_pes sending fields as frames: - * do not generate a bad frame for the first field picture - */ - if (!got_one_picture && (this->size || this->video_step || this->assume_bad_field_picture)) { - /* skipped frame, output a bad frame (use size 16x16, when size still uninitialized) */ - img = this->stream->video_out->get_frame (this->stream->video_out, - (this->bih.biWidth <= 0) ? 16 : ((this->bih.biWidth + 15) & ~15), - (this->bih.biHeight <= 0) ? 16 : ((this->bih.biHeight + 15) & ~15), - this->aspect_ratio, - this->output_format, - VO_BOTH_FIELDS|this->frame_flags); - /* set PTS to allow early syncing */ - img->pts = this->pts; - this->pts = 0; - - img->duration = video_step_to_use; - - /* additionally crop away the extra pixels due to adjusting frame size above */ - img->crop_right = ((this->bih.biWidth <= 0) ? 0 : this->crop_right) + (img->width - this->bih.biWidth); - img->crop_bottom = ((this->bih.biHeight <= 0) ? 0 : this->crop_bottom) + (img->height - this->bih.biHeight); - - img->bad_frame = 1; - this->skipframes = img->draw(img, this->stream); - img->free(img); - } - - this->assume_bad_field_picture = !got_one_picture; - } -} - -static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("processing packet type = %08x, len = %d, decoder_flags=%08x\n", - buf->type, buf->size, buf->decoder_flags); - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - - ff_handle_preview_buffer(this, buf); - - } else { - - if (buf->decoder_flags & BUF_FLAG_SPECIAL) { - - ff_handle_special_buffer(this, buf); - - } - - if (buf->decoder_flags & BUF_FLAG_HEADER) { - - ff_handle_header_buffer(this, buf); - - if (buf->decoder_flags & BUF_FLAG_ASPECT) { - if (this->aspect_ratio_prio < 3) { - this->aspect_ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2]; - this->aspect_ratio_prio = 3; - lprintf("aspect ratio: %f\n", this->aspect_ratio); - set_stream_info(this); - } - } - - } else { - - /* decode */ - if (buf->pts) - this->pts = buf->pts; - - if (this->is_mpeg12) { - ff_handle_mpeg12_buffer(this, buf); - } else { - ff_handle_buffer(this, buf); - } - - } - } -} - -static void ff_flush (video_decoder_t *this_gen) { - lprintf ("ff_flush\n"); -} - -static void ff_reset (video_decoder_t *this_gen) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("ff_reset\n"); - - this->size = 0; - - if(this->context && this->decoder_ok) - avcodec_flush_buffers(this->context); - - if (this->is_mpeg12) - mpeg_parser_reset(this->mpeg_parser); -} - -static void ff_discontinuity (video_decoder_t *this_gen) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("ff_discontinuity\n"); - this->pts = 0; -} - -static void ff_dispose (video_decoder_t *this_gen) { - ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen; - - lprintf ("ff_dispose\n"); - - if (this->decoder_ok) { - xine_list_iterator_t it; - AVFrame *av_frame; - - pthread_mutex_lock(&ffmpeg_lock); - avcodec_close (this->context); - pthread_mutex_unlock(&ffmpeg_lock); - - /* frame garbage collector here - workaround for buggy ffmpeg codecs that - * don't release their DR1 frames */ - while( (it = xine_list_front(this->dr1_frames)) != NULL ) - { - av_frame = (AVFrame *)xine_list_get_value(this->dr1_frames, it); - release_buffer(this->context, av_frame); - } - - this->stream->video_out->close(this->stream->video_out, this->stream); - this->decoder_ok = 0; - } - - if(this->context && this->context->slice_offset) - free(this->context->slice_offset); - - if(this->context && this->context->extradata) - free(this->context->extradata); - - if(this->yuv_init) - free_yuv_planes(&this->yuv); - - if( this->context ) - free( this->context ); - - if( this->av_frame ) - free( this->av_frame ); - - if (this->buf) - free(this->buf); - this->buf = NULL; - - if(this->pp_context) - pp_free_context(this->pp_context); - - if(this->pp_mode) - pp_free_mode(this->pp_mode); - - mpeg_parser_dispose(this->mpeg_parser); - - xine_list_delete(this->dr1_frames); - - free (this_gen); -} - -static video_decoder_t *ff_video_open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - ff_video_decoder_t *this ; - - lprintf ("open_plugin\n"); - - this = (ff_video_decoder_t *) xine_xmalloc (sizeof (ff_video_decoder_t)); - - this->video_decoder.decode_data = ff_decode_data; - this->video_decoder.flush = ff_flush; - this->video_decoder.reset = ff_reset; - this->video_decoder.discontinuity = ff_discontinuity; - this->video_decoder.dispose = ff_dispose; - this->size = 0; - - this->stream = stream; - this->class = (ff_video_class_t *) class_gen; - - this->av_frame = avcodec_alloc_frame(); - this->context = avcodec_alloc_context(); - this->context->opaque = this; - this->context->palctrl = NULL; - - this->decoder_ok = 0; - this->decoder_init_mode = 1; - this->buf = xine_xmalloc(VIDEOBUFSIZE + FF_INPUT_BUFFER_PADDING_SIZE); - this->bufsize = VIDEOBUFSIZE; - - this->is_mpeg12 = 0; - this->aspect_ratio = 0; - - this->pp_quality = 0; - this->pp_context = NULL; - this->pp_mode = NULL; - - this->mpeg_parser = NULL; - - this->dr1_frames = xine_list_new(); - - return &this->video_decoder; -} - -static char *ff_video_get_identifier (video_decoder_class_t *this) { - return "ffmpeg video"; -} - -static char *ff_video_get_description (video_decoder_class_t *this) { - return "ffmpeg based video decoder plugin"; -} - -static void ff_video_dispose_class (video_decoder_class_t *this) { - free (this); -} - -void *init_video_plugin (xine_t *xine, void *data) { - - ff_video_class_t *this; - config_values_t *config; - - this = (ff_video_class_t *) xine_xmalloc (sizeof (ff_video_class_t)); - - this->decoder_class.open_plugin = ff_video_open_plugin; - this->decoder_class.get_identifier = ff_video_get_identifier; - this->decoder_class.get_description = ff_video_get_description; - this->decoder_class.dispose = ff_video_dispose_class; - this->xine = xine; - - pthread_once( &once_control, init_once_routine ); - - /* Configuration for post processing quality - default to mid (3) for the - * moment */ - config = xine->config; - - this->pp_quality = xine->config->register_range(config, "video.processing.ffmpeg_pp_quality", 3, - 0, PP_QUALITY_MAX, - _("MPEG-4 postprocessing quality"), - _("You can adjust the amount of post processing applied to MPEG-4 video.\n" - "Higher values result in better quality, but need more CPU. Lower values may " - "result in image defects like block artifacts. For high quality content, " - "too heavy post processing can actually make the image worse by blurring it " - "too much."), - 10, pp_quality_cb, this); - - this->thread_count = xine->config->register_num(config, "video.processing.ffmpeg_thread_count", 1, - _("FFmpeg video decoding thread count"), - _("You can adjust the number of video decoding threads which FFmpeg may use.\n" - "Higher values should speed up decoding but it depends on the codec used " - "whether parallel decoding is supported. A rule of thumb is to have one " - "decoding thread per logical CPU (typically 1 to 4).\n" - "A change of this setting will take effect with playing the next stream."), - 10, thread_count_cb, this); - - this->skip_loop_filter_enum = xine->config->register_enum(config, "video.processing.ffmpeg_skip_loop_filter", 0, - (char **)skip_loop_filter_enum_names, - _("Skip loop filter"), - _("You can control for which frames the loop filter shall be skipped after " - "decoding.\n" - "Skipping the loop filter will speedup decoding but may lead to artefacts. " - "The number of frames for which it is skipped increases from 'none' to 'all'. " - "The default value leaves the decision up to the implementation.\n" - "A change of this setting will take effect with playing the next stream."), - 10, skip_loop_filter_enum_cb, this); - - this->choose_speed_over_accuracy = xine->config->register_bool(config, "video.processing.ffmpeg_choose_speed_over_accuracy", 0, - _("Choose speed over specification compliance"), - _("You may want to allow speed cheats which violate codec specification.\n" - "Cheating may speed up decoding but can also lead to decoding artefacts.\n" - "A change of this setting will take effect with playing the next stream."), - 10, choose_speed_over_accuracy_cb, this); - - return this; -} - -static uint32_t supported_video_types[] = { - #ifdef CONFIG_MSMPEG4V1_DECODER - BUF_VIDEO_MSMPEG4_V1, - #endif - #ifdef CONFIG_MSMPEG4V2_DECODER - BUF_VIDEO_MSMPEG4_V2, - #endif - #ifdef CONFIG_MSMPEG4V3_DECODER - BUF_VIDEO_MSMPEG4_V3, - #endif - #ifdef CONFIG_WMV1_DECODER - BUF_VIDEO_WMV7, - #endif - #ifdef CONFIG_WMV2_DECODER - BUF_VIDEO_WMV8, - #endif - #ifdef CONFIG_WMV3_DECODER - BUF_VIDEO_WMV9, - #endif - #ifdef CONFIG_VC1_DECODER - BUF_VIDEO_VC1, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_MPEG4, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_XVID, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_DIVX5, - #endif - #ifdef CONFIG_MPEG4_DECODER - BUF_VIDEO_3IVX, - #endif - #ifdef CONFIG_MJPEG_DECODER - BUF_VIDEO_JPEG, - #endif - #ifdef CONFIG_MJPEG_DECODER - BUF_VIDEO_MJPEG, - #endif - #ifdef CONFIG_MJPEGB_DECODER - BUF_VIDEO_MJPEG_B, - #endif - #ifdef CONFIG_H263I_DECODER - BUF_VIDEO_I263, - #endif - #ifdef CONFIG_H263_DECODER - BUF_VIDEO_H263, - #endif - #ifdef CONFIG_RV10_DECODER - BUF_VIDEO_RV10, - #endif - #ifdef CONFIG_RV20_DECODER - BUF_VIDEO_RV20, - #endif - #ifdef CONFIG_INDEO3_DECODER - BUF_VIDEO_IV31, - #endif - #ifdef CONFIG_INDEO3_DECODER - BUF_VIDEO_IV32, - #endif - #ifdef CONFIG_SVQ1_DECODER - BUF_VIDEO_SORENSON_V1, - #endif - #ifdef CONFIG_SVQ3_DECODER - BUF_VIDEO_SORENSON_V3, - #endif - #ifdef CONFIG_DVVIDEO_DECODER - BUF_VIDEO_DV, - #endif - #ifdef CONFIG_HUFFYUV_DECODER - BUF_VIDEO_HUFFYUV, - #endif - #ifdef CONFIG_VP3_DECODER - BUF_VIDEO_VP31, - #endif - #ifdef CONFIG_VP5_DECODER - BUF_VIDEO_VP5, - #endif - #ifdef CONFIG_VP6_DECODER - BUF_VIDEO_VP6, - BUF_VIDEO_VP6F, - #endif - #ifdef CONFIG_4XM_DECODER - BUF_VIDEO_4XM, - #endif - #ifdef CONFIG_CINEPAK_DECODER - BUF_VIDEO_CINEPAK, - #endif - #ifdef CONFIG_MSVIDEO1_DECODER - BUF_VIDEO_MSVC, - #endif - #ifdef CONFIG_MSRLE_DECODER - BUF_VIDEO_MSRLE, - #endif - #ifdef CONFIG_RPZA_DECODER - BUF_VIDEO_RPZA, - #endif - #ifdef CONFIG_CYUV_DECODER - BUF_VIDEO_CYUV, - #endif - #ifdef CONFIG_ROQ_DECODER - BUF_VIDEO_ROQ, - #endif - #ifdef CONFIG_IDCIN_DECODER - BUF_VIDEO_IDCIN, - #endif - #ifdef CONFIG_XAN_WC3_DECODER - BUF_VIDEO_WC3, - #endif - #ifdef CONFIG_WS_VQA_DECODER - BUF_VIDEO_VQA, - #endif - #ifdef CONFIG_INTERPLAY_VIDEO_DECODER - BUF_VIDEO_INTERPLAY, - #endif - #ifdef CONFIG_FLIC_DECODER - BUF_VIDEO_FLI, - #endif - #ifdef CONFIG_8BPS_DECODER - BUF_VIDEO_8BPS, - #endif - #ifdef CONFIG_SMC_DECODER - BUF_VIDEO_SMC, - #endif - #ifdef CONFIG_TRUEMOTION1_DECODER - BUF_VIDEO_DUCKTM1, - #endif - #ifdef CONFIG_TRUEMOTION2_DECODER - BUF_VIDEO_DUCKTM2, - #endif - #ifdef CONFIG_VMDVIDEO_DECODER - BUF_VIDEO_VMD, - #endif - #ifdef CONFIG_ZLIB_DECODER - BUF_VIDEO_ZLIB, - #endif - #ifdef CONFIG_MSZH_DECODER - BUF_VIDEO_MSZH, - #endif - #ifdef CONFIG_ASV1_DECODER - BUF_VIDEO_ASV1, - #endif - #ifdef CONFIG_ASV2_DECODER - BUF_VIDEO_ASV2, - #endif - #ifdef CONFIG_VCR1_DECODER - BUF_VIDEO_ATIVCR1, - #endif - #ifdef CONFIG_FLV_DECODER - BUF_VIDEO_FLV1, - #endif - #ifdef CONFIG_QTRLE_DECODER - BUF_VIDEO_QTRLE, - #endif - #ifdef CONFIG_H264_DECODER - BUF_VIDEO_H264, - #endif - #ifdef CONFIG_H261_DECODER - BUF_VIDEO_H261, - #endif - #ifdef CONFIG_AASC_DECODER - BUF_VIDEO_AASC, - #endif - #ifdef CONFIG_LOCO_DECODER - BUF_VIDEO_LOCO, - #endif - #ifdef CONFIG_QDRAW_DECODER - BUF_VIDEO_QDRW, - #endif - #ifdef CONFIG_QPEG_DECODER - BUF_VIDEO_QPEG, - #endif - #ifdef CONFIG_TSCC_DECODER - BUF_VIDEO_TSCC, - #endif - #ifdef CONFIG_ULTI_DECODER - BUF_VIDEO_ULTI, - #endif - #ifdef CONFIG_WNV1_DECODER - BUF_VIDEO_WNV1, - #endif - #ifdef CONFIG_VIXL_DECODER - BUF_VIDEO_XL, - #endif - #ifdef CONFIG_INDEO2_DECODER - BUF_VIDEO_RT21, - #endif - #ifdef CONFIG_FRAPS_DECODER - BUF_VIDEO_FPS1, - #endif - #ifdef CONFIG_MPEG1VIDEO_DECODER - BUF_VIDEO_MPEG, - #endif - #ifdef CONFIG_CSCD_DECODER - BUF_VIDEO_CSCD, - #endif - #ifdef CONFIG_AVS_DECODER - BUF_VIDEO_AVS, - #endif - #ifdef CONFIG_MMVIDEO_DECODER - BUF_VIDEO_ALGMM, - #endif - #ifdef CONFIG_ZMBV_DECODER - BUF_VIDEO_ZMBV, - #endif - #ifdef CONFIG_SMACKVIDEO_DECODER - BUF_VIDEO_SMACKER, - #endif - #ifdef CONFIG_NUV_DECODER - BUF_VIDEO_NUV, - #endif - #ifdef CONFIG_KMVC_DECODER - BUF_VIDEO_KMVC, - #endif - #ifdef CONFIG_FLASHSV_DECODER - BUF_VIDEO_FLASHSV, - #endif - #ifdef CONFIG_CAVS_DECODER - BUF_VIDEO_CAVS, - #endif - #ifdef CONFIG_VMNC_DECODER - BUF_VIDEO_VMNC, - #endif - BUF_VIDEO_THEORA_RAW, - 0 -}; - -static uint32_t wmv8_video_types[] = { - BUF_VIDEO_WMV8, - 0 -}; - -static uint32_t wmv9_video_types[] = { - BUF_VIDEO_WMV9, - 0 -}; - -decoder_info_t dec_info_ffmpeg_video = { - supported_video_types, /* supported types */ - 6 /* priority */ -}; - -decoder_info_t dec_info_ffmpeg_wmv8 = { - wmv8_video_types, /* supported types */ - 0 /* priority */ -}; - -decoder_info_t dec_info_ffmpeg_wmv9 = { - wmv9_video_types, /* supported types */ - 0 /* priority */ -}; diff --git a/src/libffmpeg/ffmpeg_decoder.c b/src/libffmpeg/ffmpeg_decoder.c deleted file mode 100644 index d0175184f..000000000 --- a/src/libffmpeg/ffmpeg_decoder.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (C) 2001-2004 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * xine decoder plugin using ffmpeg - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "ffmpeg_config.h" -#endif - -#include "xine_internal.h" - -#include "ffmpeg_decoder.h" - -/* - * common initialisation - */ - -pthread_once_t once_control = PTHREAD_ONCE_INIT; -pthread_mutex_t ffmpeg_lock; - -#ifndef HAVE_FFMPEG - -#define REGISTER_ENCODER(X,x) \ - if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder) -#define REGISTER_DECODER(X,x) \ - if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder) -#define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x) - -#define REGISTER_PARSER(X,x) \ - if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser) - -/* If you do not call this function, then you can select exactly which - formats you want to support */ - -/** - * simple call to register all the codecs. - */ -void avcodec_register_all(void) -{ - static int inited = 0; - - if (inited != 0) - return; - inited = 1; - - /* video codecs */ - REGISTER_DECODER(AASC, aasc); - REGISTER_ENCDEC (ASV1, asv1); - REGISTER_ENCDEC (ASV2, asv2); - REGISTER_DECODER(AVS, avs); - REGISTER_DECODER(BMP, bmp); - REGISTER_DECODER(CAVS, cavs); - REGISTER_DECODER(CINEPAK, cinepak); - REGISTER_DECODER(CLJR, cljr); - REGISTER_DECODER(CSCD, cscd); - REGISTER_DECODER(CYUV, cyuv); - REGISTER_DECODER(DSICINVIDEO, dsicinvideo); - REGISTER_ENCDEC (DVVIDEO, dvvideo); - REGISTER_DECODER(EIGHTBPS, eightbps); - REGISTER_ENCDEC (FFV1, ffv1); - REGISTER_ENCDEC (FFVHUFF, ffvhuff); - REGISTER_DECODER(FLASHSV, flashsv); - REGISTER_DECODER(FLIC, flic); - REGISTER_ENCDEC (FLV, flv); - REGISTER_DECODER(FOURXM, fourxm); - REGISTER_DECODER(FRAPS, fraps); - REGISTER_ENCDEC (GIF, gif); - REGISTER_ENCDEC (H261, h261); - REGISTER_ENCDEC (H263, h263); - REGISTER_DECODER(H263I, h263i); - REGISTER_ENCODER(H263P, h263p); - REGISTER_DECODER(H264, h264); - REGISTER_ENCDEC (HUFFYUV, huffyuv); - REGISTER_DECODER(IDCIN, idcin); - REGISTER_DECODER(INDEO2, indeo2); - REGISTER_DECODER(INDEO3, indeo3); - REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video); - REGISTER_ENCODER(JPEGLS, jpegls); - REGISTER_DECODER(KMVC, kmvc); - REGISTER_ENCODER(LJPEG, ljpeg); - REGISTER_DECODER(LOCO, loco); - REGISTER_DECODER(MDEC, mdec); - REGISTER_ENCDEC (MJPEG, mjpeg); - REGISTER_DECODER(MJPEGB, mjpegb); - REGISTER_DECODER(MMVIDEO, mmvideo); -#ifdef HAVE_XVMC - REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc); -#endif - REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); - REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); - REGISTER_ENCDEC (MPEG4, mpeg4); - REGISTER_DECODER(MPEGVIDEO, mpegvideo); - REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); - REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); - REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); - REGISTER_DECODER(MSRLE, msrle); - REGISTER_DECODER(MSVIDEO1, msvideo1); - REGISTER_DECODER(MSZH, mszh); - REGISTER_DECODER(NUV, nuv); - REGISTER_ENCODER(PAM, pam); - REGISTER_ENCODER(PBM, pbm); - REGISTER_ENCODER(PGM, pgm); - REGISTER_ENCODER(PGMYUV, pgmyuv); -#ifdef CONFIG_ZLIB - REGISTER_ENCDEC (PNG, png); -#endif - REGISTER_ENCODER(PPM, ppm); - REGISTER_DECODER(QDRAW, qdraw); - REGISTER_DECODER(QPEG, qpeg); - REGISTER_DECODER(QTRLE, qtrle); - REGISTER_ENCDEC (RAWVIDEO, rawvideo); - REGISTER_DECODER(ROQ, roq); - REGISTER_DECODER(RPZA, rpza); - REGISTER_ENCDEC (RV10, rv10); - REGISTER_ENCDEC (RV20, rv20); - REGISTER_DECODER(SMACKER, smacker); - REGISTER_DECODER(SMC, smc); - REGISTER_ENCDEC (SNOW, snow); - REGISTER_DECODER(SP5X, sp5x); - REGISTER_ENCDEC (SVQ1, svq1); - REGISTER_DECODER(SVQ3, svq3); - REGISTER_DECODER(TARGA, targa); - REGISTER_DECODER(THEORA, theora); - REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo); - REGISTER_DECODER(TIFF, tiff); - REGISTER_DECODER(TRUEMOTION1, truemotion1); - REGISTER_DECODER(TRUEMOTION2, truemotion2); - REGISTER_DECODER(TSCC, tscc); - REGISTER_DECODER(ULTI, ulti); - REGISTER_DECODER(VC1, vc1); - REGISTER_DECODER(VCR1, vcr1); - REGISTER_DECODER(VMDVIDEO, vmdvideo); - REGISTER_DECODER(VMNC, vmnc); - REGISTER_DECODER(VP3, vp3); - REGISTER_DECODER(VP5, vp5); - REGISTER_DECODER(VP6, vp6); - REGISTER_DECODER(VP6F, vp6f); - REGISTER_DECODER(VQA, vqa); - REGISTER_ENCDEC (WMV1, wmv1); - REGISTER_ENCDEC (WMV2, wmv2); - REGISTER_DECODER(WMV3, wmv3); - REGISTER_DECODER(WNV1, wnv1); -#ifdef CONFIG_X264 - REGISTER_ENCODER(X264, x264); -#endif - REGISTER_DECODER(XAN_WC3, xan_wc3); - REGISTER_DECODER(XL, xl); -#ifdef CONFIG_XVID - REGISTER_ENCODER(XVID, xvid); -#endif - REGISTER_ENCDEC (ZLIB, zlib); -#ifdef CONFIG_ZLIB - REGISTER_ENCDEC (ZMBV, zmbv); -#endif - - /* audio codecs */ -#ifdef CONFIG_LIBFAAD - REGISTER_DECODER(AAC, aac); - REGISTER_DECODER(MPEG4AAC, mpeg4aac); -#endif -#ifdef CONFIG_LIBA52 - REGISTER_DECODER(AC3, ac3); -#endif - REGISTER_ENCODER(AC3, ac3); - REGISTER_DECODER(ALAC, alac); -#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) - REGISTER_ENCDEC (AMR_NB, amr_nb); -#endif -#ifdef CONFIG_AMR_WB - REGISTER_ENCDEC (AMR_WB, amr_wb); -#endif - REGISTER_DECODER(COOK, cook); - REGISTER_DECODER(DSICINAUDIO, dsicinaudio); -#ifdef CONFIG_LIBDTS - REGISTER_DECODER(DTS, dts); -#endif -#ifdef CONFIG_LIBFAAC - REGISTER_ENCODER(FAAC, faac); -#endif - REGISTER_ENCDEC (FLAC, flac); - REGISTER_DECODER(IMC, imc); -#ifdef CONFIG_LIBGSM - REGISTER_ENCDEC (LIBGSM, libgsm); -#endif - REGISTER_DECODER(MACE3, mace3); - REGISTER_DECODER(MACE6, mace6); - REGISTER_ENCDEC (MP2, mp2); - REGISTER_DECODER(MP3, mp3); - REGISTER_DECODER(MP3ADU, mp3adu); -#ifdef CONFIG_LIBMP3LAME - REGISTER_ENCODER(MP3LAME, mp3lame); -#endif - REGISTER_DECODER(MP3ON4, mp3on4); - REGISTER_DECODER(MPC7, mpc7); -#ifdef CONFIG_LIBVORBIS - if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis); - if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis); -#endif - REGISTER_DECODER(QDM2, qdm2); - REGISTER_DECODER(RA_144, ra_144); - REGISTER_DECODER(RA_288, ra_288); - REGISTER_DECODER(SHORTEN, shorten); - REGISTER_DECODER(SMACKAUD, smackaud); - REGISTER_ENCDEC (SONIC, sonic); - REGISTER_ENCODER(SONIC_LS, sonic_ls); - REGISTER_DECODER(TRUESPEECH, truespeech); - REGISTER_DECODER(TTA, tta); - REGISTER_DECODER(VMDAUDIO, vmdaudio); - REGISTER_ENCDEC (VORBIS, vorbis); - REGISTER_DECODER(WAVPACK, wavpack); - REGISTER_DECODER(WMAV1, wmav1); - REGISTER_DECODER(WMAV2, wmav2); - REGISTER_DECODER(WS_SND1, ws_snd1); - - /* pcm codecs */ - REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); - REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); - REGISTER_ENCDEC (PCM_S8, pcm_s8); - REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); - REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); - REGISTER_ENCDEC (PCM_S24BE, pcm_s24be); - REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud); - REGISTER_ENCDEC (PCM_S24LE, pcm_s24le); - REGISTER_ENCDEC (PCM_S32BE, pcm_s32be); - REGISTER_ENCDEC (PCM_S32LE, pcm_s32le); - REGISTER_ENCDEC (PCM_U8, pcm_u8); - REGISTER_ENCDEC (PCM_U16BE, pcm_u16be); - REGISTER_ENCDEC (PCM_U16LE, pcm_u16le); - REGISTER_ENCDEC (PCM_U24BE, pcm_u24be); - REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); - REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); - REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); - - /* dpcm codecs */ - REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm); - REGISTER_DECODER(ROQ_DPCM, roq_dpcm); - REGISTER_DECODER(SOL_DPCM, sol_dpcm); - REGISTER_DECODER(XAN_DPCM, xan_dpcm); - - /* adpcm codecs */ - REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm); - REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx); - REGISTER_ENCDEC (ADPCM_CT, adpcm_ct); - REGISTER_ENCDEC (ADPCM_EA, adpcm_ea); - REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); - REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3); - REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4); - REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt); - REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); - REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); - REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws); - REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); - REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2); - REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3); - REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4); - REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf); - REGISTER_ENCDEC (ADPCM_XA, adpcm_xa); - REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha); - - /* subtitles */ - REGISTER_ENCDEC (DVBSUB, dvbsub); - REGISTER_ENCDEC (DVDSUB, dvdsub); - - /* parsers */ - REGISTER_PARSER (AAC, aac); - REGISTER_PARSER (AC3, ac3); - REGISTER_PARSER (CAVSVIDEO, cavsvideo); - REGISTER_PARSER (DVBSUB, dvbsub); - REGISTER_PARSER (DVDSUB, dvdsub); - REGISTER_PARSER (H261, h261); - REGISTER_PARSER (H263, h263); - REGISTER_PARSER (H264, h264); - REGISTER_PARSER (MJPEG, mjpeg); - REGISTER_PARSER (MPEG4VIDEO, mpeg4video); - REGISTER_PARSER (MPEGAUDIO, mpegaudio); - REGISTER_PARSER (MPEGVIDEO, mpegvideo); - REGISTER_PARSER (PNM, pnm); - - /* - av_register_bitstream_filter(&dump_extradata_bsf); - av_register_bitstream_filter(&remove_extradata_bsf); - av_register_bitstream_filter(&noise_bsf); - av_register_bitstream_filter(&mp3_header_compress_bsf); - av_register_bitstream_filter(&mp3_header_decompress_bsf); - av_register_bitstream_filter(&mjpega_dump_header_bsf); - */ -} - -#endif - -void init_once_routine(void) { - pthread_mutex_init(&ffmpeg_lock, NULL); - avcodec_init(); - avcodec_register_all(); -} - -/* - * exported plugin catalog entry - */ - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER | PLUGIN_MUST_PRELOAD, 18, "ffmpegvideo", XINE_VERSION_CODE, &dec_info_ffmpeg_video, init_video_plugin }, - { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv8", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv8, init_video_plugin }, - { PLUGIN_VIDEO_DECODER, 18, "ffmpeg-wmv9", XINE_VERSION_CODE, &dec_info_ffmpeg_wmv9, init_video_plugin }, - { PLUGIN_AUDIO_DECODER, 15, "ffmpegaudio", XINE_VERSION_CODE, &dec_info_ffmpeg_audio, init_audio_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libffmpeg/ffmpeg_decoder.h b/src/libffmpeg/ffmpeg_decoder.h deleted file mode 100644 index 6de9e8772..000000000 --- a/src/libffmpeg/ffmpeg_decoder.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2001-2005 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - */ - -#ifndef HAVE_XINE_DECODER_H -#define HAVE_XINE_DECODER_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_FFMPEG_AVUTIL_H -# include -#else -# include -#endif - -typedef struct ff_codec_s { - uint32_t type; - enum CodecID id; - const char *name; -} ff_codec_t; - -void *init_audio_plugin (xine_t *xine, void *data); -void *init_video_plugin (xine_t *xine, void *data); - -extern decoder_info_t dec_info_ffmpeg_video; -extern decoder_info_t dec_info_ffmpeg_wmv8; -extern decoder_info_t dec_info_ffmpeg_wmv9; -extern decoder_info_t dec_info_ffmpeg_audio; - -extern pthread_once_t once_control; -void init_once_routine(void); - -extern pthread_mutex_t ffmpeg_lock; - -#endif diff --git a/src/libffmpeg/ffmpeg_encoder.c b/src/libffmpeg/ffmpeg_encoder.c deleted file mode 100644 index c8a450b0d..000000000 --- a/src/libffmpeg/ffmpeg_encoder.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (C) 2000-2004 the xine project - * - * This file is part of xine, a unix video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - */ - -/* mpeg encoders for the dxr3 video out plugin. */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#define LOG_MODULE "dxr3_mpeg_encoder" -/* #define LOG_VERBOSE */ -/* #define LOG */ - -#include "video_out_dxr3.h" - -#ifdef HAVE_FFMPEG -# include -#else -# include "libavcodec/avcodec.h" -#endif - -/* buffer size for encoded mpeg1 stream; will hold one intra frame - * at 640x480 typical sizes are <50 kB. 512 kB should be plenty */ -#define DEFAULT_BUFFER_SIZE 512*1024 - - -/*initialisation function, used by the dxr3 plugin */ -int dxr3_encoder_init(dxr3_driver_t *drv) EXPORTED; - -/* functions required by encoder api */ -static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame); -static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame); -static int lavc_on_unneeded(dxr3_driver_t *drv); - -/*encoder structure*/ -typedef struct lavc_data_s { - encoder_data_t encoder_data; - AVCodecContext *context; /* handle for encoding */ - int width, height; /* width and height of the video frame */ - uint8_t *ffmpeg_buffer; /* lavc buffer */ - AVFrame *picture; /* picture to be encoded */ - uint8_t *out[3]; /* aligned buffer for YV12 data */ - uint8_t *buf; /* unaligned YV12 buffer */ -} lavc_data_t; - - -int dxr3_encoder_init(dxr3_driver_t *drv) -{ - lavc_data_t* this; - avcodec_init(); - - avcodec_register_all(); - lprintf("lavc init , version %x\n", avcodec_version()); - this = xine_xmalloc(sizeof(lavc_data_t)); - if (!this) return 0; - - this->encoder_data.type = ENC_LAVC; - this->encoder_data.on_update_format = lavc_on_update_format; - this->encoder_data.on_frame_copy = NULL; - this->encoder_data.on_display_frame = lavc_on_display_frame; - this->encoder_data.on_unneeded = lavc_on_unneeded; - this->context = 0; - - drv->enc = &this->encoder_data; - return 1; -} - -/* helper function */ -static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame); - -static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - lavc_data_t *this = (lavc_data_t *)drv->enc; - AVCodec *codec; - unsigned char use_quantizer; - - if (this->context) { - avcodec_close(this->context); - free(this->context); - free(this->picture); - this->context = NULL; - this->picture = NULL; - } - - /* if YUY2 and dimensions changed, we need to re-allocate the - * internal YV12 buffer */ - if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { - int image_size = frame->vo_frame.pitches[0] * frame->oheight; - - this->out[0] = xine_xmalloc_aligned(16, image_size * 3/2, - (void *)&this->buf); - this->out[1] = this->out[0] + image_size; - this->out[2] = this->out[1] + image_size/4; - - /* fill with black (yuv 16,128,128) */ - memset(this->out[0], 16, image_size); - memset(this->out[1], 128, image_size/4); - memset(this->out[2], 128, image_size/4); - lprintf("Using YUY2->YV12 conversion\n"); - } - - /* resolution must be a multiple of two */ - if ((frame->vo_frame.pitches[0] % 2 != 0) || (frame->oheight % 2 != 0)) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: lavc only handles video dimensions which are multiples of 2\n"); - return 0; - } - - /* get mpeg codec handle */ - codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); - if (!codec) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: lavc MPEG1 codec not found\n"); - return 0; - } - lprintf("lavc MPEG1 encoder found.\n"); - - this->width = frame->vo_frame.pitches[0]; - this->height = frame->oheight; - - this->context = avcodec_alloc_context(); - if (!this->context) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't start the ffmpeg library\n"); - return 0; - } - this->picture = avcodec_alloc_frame(); - if (!this->picture) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't allocate ffmpeg frame\n"); - return 0; - } - - /* mpeg1 encoder only support YUV420P */ - this->context->pix_fmt = PIX_FMT_YUVJ420P; - - /* put sample parameters */ - this->context->bit_rate = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_bitrate", 10000, 1000, 20000, - _("libavcodec mpeg output bitrate (kbit/s)"), - _("The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. " - "Higher values will increase quality and CPU usage.\n" - "This setting is only considered, when constant quality mode is disabled."), 10, NULL, NULL); - this->context->bit_rate *= 1000; /* config in kbit/s, libavcodec wants bit/s */ - - use_quantizer = drv->class->xine->config->register_bool(drv->class->xine->config, - "dxr3.encoding.lavc_quantizer", 1, - _("constant quality mode"), - _("When enabled, libavcodec will use a constant quality mode by dynamically " - "compressing the images based on their complexity. When disabled, libavcodec " - "will use constant bitrate mode."), 10, NULL, NULL); - - if (use_quantizer) { - this->context->qmin = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_qmin", 1, 1, 10, - _("minimum compression"), - _("The minimum compression to apply to an image in constant quality mode."), - 10, NULL, NULL); - - this->context->qmax = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_qmax", 2, 1, 20, - _("maximum quantizer"), - _("The maximum compression to apply to an image in constant quality mode."), - 10, NULL, NULL); - } - - lprintf("lavc -> bitrate %d \n", this->context->bit_rate); - - this->context->width = frame->vo_frame.pitches[0]; - this->context->height = frame->oheight; - - this->context->gop_size = 0; /*intra frames only */ - this->context->me_method = ME_ZERO; /*motion estimation type*/ - - this->context->time_base.den = 90000; - if (frame->vo_frame.duration > 90000 / 24) - this->context->time_base.num = 90000 / 24; - else if (frame->vo_frame.duration < 90000 / 60) - this->context->time_base.num = 90000 / 60; - else - this->context->time_base.num = frame->vo_frame.duration; - /* ffmpeg can complain about illegal framerates, but since this seems no - * problem for the DXR3, we just tell ffmpeg to be more lax with */ - this->context->strict_std_compliance = -1; - - /* open avcodec */ - if (avcodec_open(this->context, codec) < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, "dxr3_mpeg_encoder: could not open codec\n"); - return 0; - } - lprintf("dxr3_mpeg_encoder: lavc MPEG1 codec opened.\n"); - - if (!this->ffmpeg_buffer) - this->ffmpeg_buffer = (unsigned char *)malloc(DEFAULT_BUFFER_SIZE); /* why allocate more than needed ?! */ - if (!this->ffmpeg_buffer) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't allocate temp buffer for mpeg data\n"); - return 0; - } - - return 1; -} - -static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - int size; - lavc_data_t* this = (lavc_data_t *)drv->enc; - ssize_t written; - - if (frame->vo_frame.bad_frame) return 1; - /* ignore old frames */ - if ((frame->vo_frame.pitches[0] != this->context->width) || (frame->oheight != this->context->height)) { - frame->vo_frame.free(&frame->vo_frame); - lprintf("LAVC ignoring frame !!!\n"); - return 1; - } - - /* prepare frame for conversion, handles YUY2 -> YV12 conversion when necessary */ - lavc_prepare_frame(this, drv, frame); - - /* do the encoding */ - size = avcodec_encode_video(this->context, this->ffmpeg_buffer, DEFAULT_BUFFER_SIZE, this->picture); - - frame->vo_frame.free(&frame->vo_frame); - - if (size < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: encoding failed\n"); - return 0; - } - - written = write(drv->fd_video, this->ffmpeg_buffer, size); - if (written < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: video device write failed (%s)\n", strerror(errno)); - return 0; - } - if (written != size) - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Could only write %zd of %d mpeg bytes.\n", written, size); - return 1; -} - -static int lavc_on_unneeded(dxr3_driver_t *drv) -{ - lavc_data_t *this = (lavc_data_t *)drv->enc; - lprintf("flushing buffers\n"); - if (this->context) { - avcodec_close(this->context); - free(this->context); - free(this->picture); - this->context = NULL; - this->picture = NULL; - } - return 1; -} - -static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - int i, j, w2; - uint8_t *yuy2; - - if (frame->vo_frame.bad_frame) return 1; - - if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { - /* need YUY2->YV12 conversion */ - if (!(this->out[0] && this->out[1] && this->out[2]) ) { - lprintf("Internal YV12 buffer not created.\n"); - return 0; - } - this->picture->data[0] = this->out[0] + frame->vo_frame.pitches[0] * drv->top_bar; /* y */ - this->picture->data[1] = this->out[1] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* u */ - this->picture->data[2] = this->out[2] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* v */ - yuy2 = frame->vo_frame.base[0]; - w2 = frame->vo_frame.pitches[0] / 2; - for (i = 0; i < frame->vo_frame.height; i += 2) { - for (j = 0; j < w2; j++) { - /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */ - *(this->picture->data[0]++) = *(yuy2++); - *(this->picture->data[1]++) = *(yuy2++); - *(this->picture->data[0]++) = *(yuy2++); - *(this->picture->data[2]++) = *(yuy2++); - } - /* down sampling */ - for (j = 0; j < w2; j++) { - /* skip every second line for U and V */ - *(this->picture->data[0]++) = *(yuy2++); - yuy2++; - *(this->picture->data[0]++) = *(yuy2++); - yuy2++; - } - } - /* reset for encoder */ - this->picture->data[0] = this->out[0]; - this->picture->data[1] = this->out[1]; - this->picture->data[2] = this->out[2]; - } - else { /* YV12 **/ - this->picture->data[0] = frame->real_base[0]; - this->picture->data[1] = frame->real_base[1]; - this->picture->data[2] = frame->real_base[2]; - } - this->picture->linesize[0] = this->context->width; - this->picture->linesize[1] = this->context->width / 2; - this->picture->linesize[2] = this->context->width / 2; - return 1; -} -- cgit v1.2.3 From 2e1b0bb57b6ce5e2c19a3a8b735c13ae42ef048c Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 19 Mar 2008 13:40:06 +0000 Subject: Fix ffmpeg plugin build where source dir != build dir. --- src/combined/ffmpeg/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/ffmpeg/Makefile.am b/src/combined/ffmpeg/Makefile.am index 741acdf40..3c78fa9d3 100644 --- a/src/combined/ffmpeg/Makefile.am +++ b/src/combined/ffmpeg/Makefile.am @@ -6,7 +6,7 @@ if HAVE_FFMPEG ff_cppflags = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) else -ff_cppflags = -I$(top_srcdir)/src/libffmpeg -I$(top_srcdir)/src/libffmpeg/libavcodec -I$(top_srcdir)/src/libffmpeg/libavutil +ff_cppflags = -I$(top_builddir)/src/libffmpeg -I$(top_srcdir)/src/libffmpeg/libavcodec -I$(top_srcdir)/src/libffmpeg/libavutil link_ffmpeg = \ $(top_builddir)/src/libffmpeg/libavcodec/libavcodec.la \ $(top_builddir)/src/libffmpeg/libavutil/libavutil.la \ -- cgit v1.2.3 From d60523d37375659965650be4c695b3d439ded174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 11 Mar 2008 15:24:55 +0100 Subject: Fix Array Indexing Vulnerability in sdpplin_parse(). (CVE-2008-0073). Thanks to Alin Rad Pop, Secunia Research. --- src/input/libreal/sdpplin.c | 23 ++++++++++++++++++++--- src/input/libreal/sdpplin.h | 4 ++-- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/input/libreal/sdpplin.c b/src/input/libreal/sdpplin.c index 5b22e9044..04554c45e 100644 --- a/src/input/libreal/sdpplin.c +++ b/src/input/libreal/sdpplin.c @@ -143,7 +143,14 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) { handled=0; if(filter(*data,"a=control:streamid=",&buf)) { - desc->stream_id=atoi(buf); + /* This way negative values are mapped to unfeasibly high + * values, and will be discarded afterward + */ + unsigned long tmp = strtoul(buf, NULL, 10); + if ( tmp > UINT16_MAX ) + lprintf("stream id out of bound: %lu\n", tmp); + else + desc->stream_id=tmp; handled=1; *data=nl(*data); } @@ -252,7 +259,10 @@ sdpplin_t *sdpplin_parse(char *data) { } stream=sdpplin_parse_stream(&data); lprintf("got data for stream id %u\n", stream->stream_id); - desc->stream[stream->stream_id]=stream; + if ( stream->stream_id >= desc->stream_count ) + lprintf("stream id %u is greater than stream count %u\n", stream->stream_id, desc->stream_count); + else + desc->stream[stream->stream_id]=stream; continue; } @@ -293,7 +303,14 @@ sdpplin_t *sdpplin_parse(char *data) { } if(filter(data,"a=StreamCount:integer;",&buf)) { - desc->stream_count=atoi(buf); + /* This way negative values are mapped to unfeasibly high + * values, and will be discarded afterward + */ + unsigned long tmp = strtoul(buf, NULL, 10); + if ( tmp > UINT16_MAX ) + lprintf("stream count out of bound: %lu\n", tmp); + else + desc->stream_count = tmp; desc->stream = calloc(desc->stream_count, sizeof(sdpplin_stream_t*)); handled=1; data=nl(data); diff --git a/src/input/libreal/sdpplin.h b/src/input/libreal/sdpplin.h index cb3b434d4..72cbaf731 100644 --- a/src/input/libreal/sdpplin.h +++ b/src/input/libreal/sdpplin.h @@ -37,7 +37,7 @@ typedef struct { char *id; char *bandwidth; - int stream_id; + uint16_t stream_id; char *range; char *length; char *rtpmap; @@ -81,7 +81,7 @@ typedef struct { int flags; int is_real_data_type; - int stream_count; + uint16_t stream_count; char *title; char *author; char *copyright; -- cgit v1.2.3 From 5feca7a3847d4035b9d4116ceb5ffd24d5ae07b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 11 Mar 2008 15:30:36 +0100 Subject: Use calloc() to avoid possible integer overflow if stream_count is big enough. --HG-- extra : transplant_source : %90%CC%97%8Fk%C1%FD%9C%A4%FB%0C%9E%07%F5A%B8%29o%EEo --- src/input/libreal/sdpplin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/input/libreal/sdpplin.c b/src/input/libreal/sdpplin.c index c62b6bbc1..5b22e9044 100644 --- a/src/input/libreal/sdpplin.c +++ b/src/input/libreal/sdpplin.c @@ -199,7 +199,7 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) { if(filter(*data,"a=OpaqueData:buffer;",&buf)) { decoded = b64_decode(buf, decoded, &(desc->mlti_data_size)); if ( decoded != NULL ) { - desc->mlti_data = malloc(sizeof(char)*desc->mlti_data_size); + desc->mlti_data = calloc(desc->mlti_data_size, sizeof(char)); memcpy(desc->mlti_data, decoded, desc->mlti_data_size); handled=1; *data=nl(*data); @@ -294,7 +294,7 @@ sdpplin_t *sdpplin_parse(char *data) { if(filter(data,"a=StreamCount:integer;",&buf)) { desc->stream_count=atoi(buf); - desc->stream = malloc(sizeof(sdpplin_stream_t*)*desc->stream_count); + desc->stream = calloc(desc->stream_count, sizeof(sdpplin_stream_t*)); handled=1; data=nl(data); } -- cgit v1.2.3 From 8405a6c9ce882f09c11963fcc0fbc2dcbac57c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Tue, 11 Mar 2008 22:21:15 +0100 Subject: Fix accessing plugin node after disposing plugin in plugin free functions. --- src/xine-engine/load_plugins.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 46535ef33..710e6dfbf 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -1339,11 +1339,13 @@ input_plugin_t *_x_find_input_plugin (xine_stream_t *stream, const char *mrl) { void _x_free_input_plugin (xine_stream_t *stream, input_plugin_t *input) { plugin_catalog_t *catalog = stream->xine->plugin_catalog; + plugin_node_t *node = input->node; input->dispose(input); - if (input->node) { + + if (node) { pthread_mutex_lock(&catalog->lock); - dec_node_ref(input->node); + dec_node_ref(node); pthread_mutex_unlock(&catalog->lock); } } @@ -1560,11 +1562,13 @@ demux_plugin_t *_x_find_demux_plugin_last_probe(xine_stream_t *stream, const cha void _x_free_demux_plugin (xine_stream_t *stream, demux_plugin_t *demux) { plugin_catalog_t *catalog = stream->xine->plugin_catalog; + plugin_node_t *node = demux->node; demux->dispose(demux); - if (demux->node) { + + if (node) { pthread_mutex_lock(&catalog->lock); - dec_node_ref(demux->node); + dec_node_ref(node); pthread_mutex_unlock(&catalog->lock); } } @@ -2054,12 +2058,13 @@ video_decoder_t *_x_get_video_decoder (xine_stream_t *stream, uint8_t stream_typ void _x_free_video_decoder (xine_stream_t *stream, video_decoder_t *vd) { plugin_catalog_t *catalog = stream->xine->plugin_catalog; + plugin_node_t *node = vd->node; vd->dispose (vd); - if (vd->node) { + if (node) { pthread_mutex_lock (&catalog->lock); - dec_node_ref(vd->node); + dec_node_ref(node); pthread_mutex_unlock (&catalog->lock); } } -- cgit v1.2.3 From 1c4e2a1b547e26f48b5797edcf54c43ba6f6e213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Tue, 11 Mar 2008 23:03:38 +0100 Subject: Fix buffer size calculation by using more appropriate calloc(). --- src/xine-engine/configfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 37a4e38ad..00665adbc 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1451,7 +1451,7 @@ static char* config_register_serialized_entry (config_values_t *this, const char if (!bytes) goto exit; if ((value_count < 0) || (value_count > 256)) goto exit; - enum_values = malloc (sizeof(void*) * value_count + 1); + enum_values = calloc (value_count + 1, sizeof(void*)); for (i = 0; i < value_count; i++) { pos += bytes = get_string(output, output_len, pos, &enum_values[i]); if (!bytes) goto exit; -- cgit v1.2.3 From fc0b8f3dcb51da6a0b1293c561cd46792c3047ad Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 12 Mar 2008 00:07:59 +0000 Subject: Tidy up ffmpeg includes a bit. -Ilibavcodec is wrong when build dir != source dir or with external ffmpeg. --- src/libffmpeg/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am index d2be74c39..efc1c18aa 100644 --- a/src/libffmpeg/Makefile.am +++ b/src/libffmpeg/Makefile.am @@ -1,12 +1,13 @@ include $(top_srcdir)/misc/Makefile.common -DEFAULT_INCLUDES = -I. -Ilibavcodec +DEFAULT_INCLUDES = -I. if HAVE_FFMPEG AM_CFLAGS = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) +ff_cppflags = link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) else -ff_cppflags = -I$(top_srcdir)/src/libffmpeg/libavutil +ff_cppflags = -I$(top_srcdir)/src/libffmpeg/libavcodec -I$(top_srcdir)/src/libffmpeg/libavutil link_ffmpeg = \ $(top_builddir)/src/libffmpeg/libavcodec/libavcodec.la \ $(top_builddir)/src/libffmpeg/libavutil/libavutil.la \ -- cgit v1.2.3 From 08765c20628cd7a38b53871390b91b16f30e8f9c Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 12 Mar 2008 00:17:11 +0000 Subject: Cope with NetBSD, which apparently doesn't have SNDCTL_DSP_GETODELAY. (Fall back on SNDCTL_DSP_GETOPTR.) --- src/audio_out/audio_oss_out.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index a6e0fe494..40d5bcfdc 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -405,6 +405,18 @@ static int ao_oss_delay(ao_driver_t *this_gen) { if (bytes_left<=0) /* buffer ran dry */ bytes_left = 0; break; + case OSS_SYNC_GETODELAY: +#ifdef SNDCTL_DSP_GETODELAY + if (ioctl (this->audio_fd, SNDCTL_DSP_GETODELAY, &bytes_left)) { + perror ("audio_oss_out: DSP_GETODELAY ioctl():"); + } + if (bytes_left<0) + bytes_left = 0; + + lprintf ("%d bytes left\n", bytes_left); + + break; +#endif case OSS_SYNC_GETOPTR: if (ioctl (this->audio_fd, SNDCTL_DSP_GETOPTR, &info)) { perror ("audio_oss_out: SNDCTL_DSP_GETOPTR failed:"); @@ -423,16 +435,6 @@ static int ao_oss_delay(ao_driver_t *this_gen) { this->bytes_in_buffer = info.bytes; } this->last_getoptr = info.bytes; - break; - case OSS_SYNC_GETODELAY: - if (ioctl (this->audio_fd, SNDCTL_DSP_GETODELAY, &bytes_left)) { - perror ("audio_oss_out: DSP_GETODELAY ioctl():"); - } - if (bytes_left<0) - bytes_left = 0; - - lprintf ("%d bytes left\n", bytes_left); - break; } @@ -840,10 +842,13 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da * check if SNDCTL_DSP_GETODELAY works. if so, using it is preferred. */ +#ifdef SNDCTL_DSP_GETODELAY if (ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &info) != -1) { xprintf(class->xine, XINE_VERBOSITY_DEBUG, "audio_oss_out: using SNDCTL_DSP_GETODELAY\n"); this->sync_method = OSS_SYNC_GETODELAY; - } else if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) != -1) { + } else +#endif + if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) != -1) { xprintf(class->xine, XINE_VERBOSITY_DEBUG, "audio_oss_out: using SNDCTL_DSP_GETOPTR\n"); this->sync_method = OSS_SYNC_GETOPTR; } else { -- cgit v1.2.3 From cdec7f82959eb05d1c3e4632af9d1e54bcc4c3bb Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 17 Mar 2008 16:06:44 +0000 Subject: Add a simple XML parser test program (not distributed). --- src/xine-utils/Makefile.am | 4 +++ src/xine-utils/xmlparser.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) (limited to 'src') diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am index 047633ad0..a7dc2b2b0 100644 --- a/src/xine-utils/Makefile.am +++ b/src/xine-utils/Makefile.am @@ -35,3 +35,7 @@ libxineutils_la_SOURCES = $(pppc_files) \ sorted_array.c \ pool.c \ ring_buffer.c + +noinst_PROGRAMS = xmltest +xmltest_SOURCES = xmllexer.c xmlparser.c +xmltest_CFLAGS = -DLOG -DXINE_XML_PARSER_TEST $(AM_CFLAGS) diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c index 8ef828105..0c3d12f59 100644 --- a/src/xine-utils/xmlparser.c +++ b/src/xine-utils/xmlparser.c @@ -837,3 +837,73 @@ void xml_parser_dump_tree (const xml_node_t *node) { node = node->next; } while (node); } + +#ifdef XINE_XML_PARSER_TEST +#include +#include +#include +#include + +void *xine_xmalloc (size_t size) +{ + return malloc (size); +} + +int main (int argc, char **argv) +{ + int i, ret = 0; + for (i = 1; argv[i]; ++i) + { + xml_node_t *tree; + int fd; + void *buf; + struct stat st; + + if (stat (argv[i], &st)) + { + perror (argv[i]); + ret = 1; + continue; + } + if (!S_ISREG (st.st_mode)) + { + printf ("%s: not a file\n", argv[i]); + ret = 1; + continue; + } + fd = open (argv[i], O_RDONLY); + if (!fd) + { + perror (argv[i]); + ret = 1; + continue; + } + buf = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (!buf) + { + perror (argv[i]); + if (close (fd)) + perror (argv[i]); + ret = 1; + continue; + } + + xml_parser_init (buf, st.st_size, 0); + if (!xml_parser_build_tree (&tree)) + { + puts (argv[i]); + xml_parser_dump_tree (tree); + xml_parser_free_tree (tree); + } + else + printf ("%s: parser failure\n", argv[i]); + + if (close (fd)) + { + perror (argv[i]); + ret = 1; + } + } + return ret; +} +#endif -- cgit v1.2.3 From a6f1d697255078f31f718a7918974233da3d7bf3 Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Mon, 24 Mar 2008 17:14:44 +0200 Subject: WAV demuxer: search for the 'fmt ' chunk instead of assuming it's the first one (fixes playback of some files) --HG-- extra : transplant_source : %F0N%EC%A4v%94%CA%1F%05%E3%E2%AC%5D8-%18c%AD%B1%E4 --- src/demuxers/demux_wav.c | 87 +++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_wav.c b/src/demuxers/demux_wav.c index 9b46336fe..f654a0f3e 100644 --- a/src/demuxers/demux_wav.c +++ b/src/demuxers/demux_wav.c @@ -41,9 +41,11 @@ #include "bswap.h" #include "group_audio.h" -#define WAV_SIGNATURE_SIZE 16 +#define WAV_SIGNATURE_SIZE 12 /* this is the hex value for 'data' */ #define data_TAG 0x61746164 +/* this is the hex value for 'fmt ' */ +#define fmt_TAG 0x20746D66 #define PCM_BLOCK_ALIGN 1024 #define PREFERED_BLOCK_SIZE 4096 @@ -73,30 +75,62 @@ typedef struct { static int demux_wav_get_stream_length (demux_plugin_t *this_gen); +/* searches for the chunk with the given tag from the beginning of WAV file + * returns 1 if chunk was found, 0 otherwise, + * fills chunk_size and chunk_pos if chunk was found + * NOTE: chunk_pos is set to the position of the first byte of chunk data */ +static int find_chunk_by_tag(demux_wav_t *this, const uint32_t given_chunk_tag, + uint32_t *found_chunk_size, off_t *found_chunk_pos) { + uint32_t chunk_tag; + uint32_t chunk_size; + uint8_t chunk_preamble[8]; + + /* search for the chunks from the start of the WAV file */ + this->input->seek(this->input, WAV_SIGNATURE_SIZE, SEEK_SET); + + while (1) { + if (this->input->read(this->input, chunk_preamble, 8) != 8) { + return 0; + } + + chunk_tag = _X_LE_32(&chunk_preamble[0]); + chunk_size = _X_LE_32(&chunk_preamble[4]); + + if (chunk_tag == given_chunk_tag) { + if (found_chunk_size) + *found_chunk_size = _X_LE_32(&chunk_preamble[4]); + if (found_chunk_pos) + *found_chunk_pos = this->input->get_current_pos(this->input); + return 1; + } else { + this->input->seek(this->input, chunk_size, SEEK_CUR); + } + } +} + /* returns 1 if the WAV file was opened successfully, 0 otherwise */ static int open_wav_file(demux_wav_t *this) { uint8_t signature[WAV_SIGNATURE_SIZE]; uint32_t chunk_tag; uint32_t chunk_size; uint8_t chunk_preamble[8]; + off_t wave_pos; /* check the signature */ if (_x_demux_read_header(this->input, signature, WAV_SIGNATURE_SIZE) != WAV_SIGNATURE_SIZE) return 0; - if (memcmp(signature, "RIFF", 4) || memcmp(&signature[8], "WAVEfmt ", 8) ) + if (memcmp(signature, "RIFF", 4) || memcmp(&signature[8], "WAVE", 4) ) return 0; - /* file is qualified; skip over the header bytes in the stream */ - this->input->seek(this->input, WAV_SIGNATURE_SIZE, SEEK_SET); - - /* go after the format structure */ - if (this->input->read(this->input, - (unsigned char *)&this->wave_size, 4) != 4) + /* search for the 'fmt ' chunk first */ + wave_pos = 0; + if (find_chunk_by_tag(this, fmt_TAG, &this->wave_size, &wave_pos)==0) return 0; - this->wave_size = le2me_32(this->wave_size); + + this->input->seek(this->input, wave_pos, SEEK_SET); this->wave = xine_xmalloc( this->wave_size ); - + if (this->input->read(this->input, (void *)this->wave, this->wave_size) != this->wave_size) { free (this->wave); @@ -113,28 +147,21 @@ static int open_wav_file(demux_wav_t *this) { return 0; } - /* traverse through the chunks to find the 'data' chunk */ + /* search for the 'data' chunk */ this->data_start = this->data_size = 0; - while (this->data_start == 0) { - - if (this->input->read(this->input, chunk_preamble, 8) != 8) { - free (this->wave); - return 0; - } - chunk_tag = _X_LE_32(&chunk_preamble[0]); - chunk_size = _X_LE_32(&chunk_preamble[4]); - - if (chunk_tag == data_TAG) { - this->data_start = this->input->get_current_pos(this->input); - /* Get the data length from the file itself, instead of the data - * TAG, for broken files */ - this->data_size = this->input->get_length(this->input); - } else { - this->input->seek(this->input, chunk_size, SEEK_CUR); - } + if (find_chunk_by_tag(this, data_TAG, &this->data_size, &this->data_start)==0) + { + free (this->wave); + return 0; + } + else + { + /* Get the data length from the file itself, instead of the data + * TAG, for broken files */ + this->input->seek(this->input, this->data_start, SEEK_SET); + this->data_size = this->input->get_length(this->input); + return 1; } - - return 1; } static int demux_wav_send_chunk(demux_plugin_t *this_gen) { -- cgit v1.2.3 From 7a29f15cf90a3629185ef1f3987e24a3910785db Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 23 Mar 2008 01:51:28 +0000 Subject: Check for failure of various memory allocations. (SA29484) Ref. http://aluigi.altervista.org/adv/xinehof-adv.txt --- src/demuxers/demux_film.c | 5 +++ src/demuxers/demux_flv.c | 16 ++++++-- src/demuxers/demux_qt.c | 85 +++++++++++++++++++++++++------------------ src/demuxers/demux_real.c | 6 ++- src/demuxers/demux_wc3movie.c | 11 +++++- src/demuxers/ebml.c | 5 +++ 6 files changed, 86 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c index 13036afc1..349c2578f 100644 --- a/src/demuxers/demux_film.c +++ b/src/demuxers/demux_film.c @@ -257,6 +257,8 @@ static int open_film_file(demux_film_t *film) { film->sample_count = _X_BE_32(&film_header[i + 12]); film->sample_table = xine_xmalloc(film->sample_count * sizeof(film_sample_t)); + if (!film->sample_table) + goto film_abort; for (j = 0; j < film->sample_count; j++) { film->sample_table[j].sample_offset = @@ -333,11 +335,14 @@ static int open_film_file(demux_film_t *film) { free(film->interleave_buffer); film->interleave_buffer = xine_xmalloc(film->sample_table[0].sample_size); + if (!film->interleave_buffer) + goto film_abort; } break; default: xine_log(film->stream->xine, XINE_LOG_MSG, _("unrecognized FILM chunk\n")); + film_abort: free (film->interleave_buffer); free (film->sample_table); free (film_header); diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index a1f0b3a7b..15afe221d 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -85,7 +85,7 @@ typedef struct { off_t filesize; flv_index_entry_t *index; - int num_indices; + unsigned int num_indices; unsigned int cur_pts; @@ -209,7 +209,7 @@ static int parse_flv_var(demux_flv_t *this, unsigned char *end = buf + size; char *str; unsigned char type; - int len, num; + unsigned int len, num; if (size < 1) return 0; @@ -283,6 +283,8 @@ static int parse_flv_var(demux_flv_t *this, str = tmp + 2; tmp += len + 2; len = parse_flv_var(this, tmp, end-tmp, str, len); + if (!len) + return 0; tmp += len; } if (*tmp++ != FLV_DATA_TYPE_ENDOBJECT) @@ -298,6 +300,8 @@ static int parse_flv_var(demux_flv_t *this, str = tmp + 2; tmp += len + 2; len = parse_flv_var(this, tmp, end-tmp, str, len); + if (!len) + return 0; tmp += len; } break; @@ -310,6 +314,8 @@ static int parse_flv_var(demux_flv_t *this, if (this->index) free(this->index); this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + if (!this->index) + return 0; this->num_indices = num; } for (num = 0; num < this->num_indices && tmp < end; num++) { @@ -326,6 +332,8 @@ static int parse_flv_var(demux_flv_t *this, if (this->index) free(this->index); this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + if (!this->index) + return 0; this->num_indices = num; } for (num = 0; num < this->num_indices && tmp < end; num++) { @@ -339,6 +347,8 @@ static int parse_flv_var(demux_flv_t *this, } while (num-- && tmp < end) { len = parse_flv_var(this, tmp, end-tmp, NULL, 0); + if (!len) + return 0; tmp += len; } break; @@ -360,7 +370,7 @@ static void parse_flv_script(demux_flv_t *this, int size) { unsigned char *end = buf + size; int len; - if (this->input->read(this->input, buf, size ) != size) { + if (!buf || this->input->read(this->input, buf, size ) != size) { this->status = DEMUX_FINISHED; free(buf); return; diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index a55a0aef3..1be93abd9 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -739,38 +739,52 @@ static void parse_meta_atom(qt_info *info, unsigned char *meta_atom) { 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; + if (info->artist) { + 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; + if (info->name) { + 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; + if (info->album) { + 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; + if (info->genre) { + 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; + if (info->comment) { + 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; + if (info->composer) { + 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; + if (info->year) { + strncpy(info->year, &meta_atom[i + 20], string_size - 1); + info->year[string_size - 1] = 0; + } } } @@ -1549,32 +1563,29 @@ static qt_error parse_reference_atom (reference_t *ref, current_atom = _X_BE_32(&ref_atom[i]); if (current_atom == RDRF_ATOM) { + size_t string_size = _X_BE_32(&ref_atom[i + 12]); + size_t url_offset = 0; + + if (string_size >= current_atom_size || i + string_size >= ref_atom_size) + return QT_NOT_A_VALID_FILE; /* if the URL starts with "http://", copy it */ - if (strncmp(&ref_atom[i + 16], "http://", 7) == 0 - || strncmp(&ref_atom[i + 16], "rtsp://", 7) == 0) { + if ( memcmp(&ref_atom[i + 16], "http://", 7) && + memcmp(&ref_atom[i + 16], "rtsp://", 7) && + base_mrl ) + url_offset = strlen(base_mrl); - /* URL is spec'd to terminate with a NULL; don't trust it */ - ref->url = xine_xmalloc(_X_BE_32(&ref_atom[i + 12]) + 1); - strncpy(ref->url, &ref_atom[i + 16], _X_BE_32(&ref_atom[i + 12])); - ref->url[_X_BE_32(&ref_atom[i + 12]) - 1] = '\0'; + /* otherwise, append relative URL to base MRL */ + string_size += url_offset; - } else { + ref->url = xine_xmalloc(string_size + 1); - int string_size; + if ( url_offset ) + strcpy(ref->url, base_mrl); - if (base_mrl) - string_size = strlen(base_mrl) + _X_BE_32(&ref_atom[i + 12]) + 1; - else - string_size = _X_BE_32(&ref_atom[i + 12]) + 1; + memcpy(ref->url + url_offset, &ref_atom[i + 16], _X_BE_32(&ref_atom[i + 12])); - /* otherwise, append relative URL to base MRL */ - ref->url = xine_xmalloc(string_size); - if (base_mrl) - strcpy(ref->url, base_mrl); - strncat(ref->url, &ref_atom[i + 16], _X_BE_32(&ref_atom[i + 12])); - ref->url[string_size - 1] = '\0'; - } + ref->url[string_size] = '\0'; debug_atom_load(" qt rdrf URL reference:\n %s\n", ref->url); @@ -1993,8 +2004,12 @@ static void parse_moov_atom(qt_info *info, unsigned char *moov_atom, info->references = (reference_t *)realloc(info->references, info->reference_count * sizeof(reference_t)); - parse_reference_atom(&info->references[info->reference_count - 1], - &moov_atom[i - 4], info->base_mrl); + error = parse_reference_atom(&info->references[info->reference_count - 1], + &moov_atom[i - 4], info->base_mrl); + if (error != QT_OK) { + info->last_error = error; + return; + } } else { 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 9206bfc74..c5096b210 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -175,7 +175,8 @@ static void real_parse_index(demux_real_t *this) { off_t original_pos = this->input->get_current_pos(this->input); unsigned char index_chunk_header[INDEX_CHUNK_HEADER_SIZE]; unsigned char index_record[INDEX_RECORD_SIZE]; - int i, entries, stream_num; + int i; + unsigned int entries, stream_num; real_index_entry_t **index; while(next_index_chunk) { @@ -230,10 +231,11 @@ static void real_parse_index(demux_real_t *this) { } } - if(index && entries) { + if(index && entries) /* Allocate memory for index */ *index = xine_xmalloc(entries * sizeof(real_index_entry_t)); + if(index && entries && *index) { /* Read index */ for(i = 0; i < entries; i++) { if(this->input->read(this->input, index_record, INDEX_RECORD_SIZE) diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c index 596d47f4a..1a839924d 100644 --- a/src/demuxers/demux_wc3movie.c +++ b/src/demuxers/demux_wc3movie.c @@ -389,6 +389,12 @@ static int open_mve_file(demux_mve_t *this) { /* load the palette chunks */ this->palettes = xine_xmalloc(this->number_of_shots * PALETTE_SIZE * sizeof(palette_entry_t)); + + if (!this->shot_offsets || !this->palettes) { + free (this->shot_offsets); + return 0; + } + 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) != @@ -460,8 +466,9 @@ static int open_mve_file(demux_mve_t *this) { case BNAM_TAG: /* load the name into the stream attributes */ - title = realloc (title, chunk_size); - if (this->input->read(this->input, title, chunk_size) != chunk_size) { + free (title); + title = malloc (chunk_size); + if (!title || this->input->read(this->input, title, chunk_size) != chunk_size) { free (title); free (this->palettes); free (this->shot_offsets); diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index ac44aecd7..cc8173c26 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -424,10 +424,15 @@ int ebml_check_header(ebml_parser_t *ebml) { case EBML_ID_DOCTYPE: { char *text = malloc(elem.len + 1); + if (!text) + return 0; text[elem.len] = '\0'; if (!ebml_read_ascii (ebml, &elem, text)) + { + free (text); return 0; + } lprintf("doctype: %s\n", text); if (ebml->doctype) -- cgit v1.2.3 From 2f6bd99aa3b9e9bee0601f90ab6e772c011c50ad Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 23 Mar 2008 15:52:33 +0000 Subject: Replace various malloc(x*sizeof(y)) with calloc(x,sizeof(y)). --- src/demuxers/demux_film.c | 2 +- src/demuxers/demux_flac.c | 2 +- src/demuxers/demux_flv.c | 4 ++-- src/demuxers/demux_mpgaudio.c | 2 +- src/demuxers/demux_qt.c | 38 ++++++++++++++++++-------------------- src/demuxers/demux_real.c | 2 +- src/demuxers/demux_tta.c | 2 +- src/demuxers/demux_vmd.c | 2 +- src/demuxers/demux_wc3movie.c | 4 ++-- 9 files changed, 28 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c index 349c2578f..60365ab4d 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)); + calloc(film->sample_count, sizeof(film_sample_t)); if (!film->sample_table) goto film_abort; for (j = 0; j < film->sample_count; j++) { diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index f6544bb67..c3d547cdb 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -164,7 +164,7 @@ 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 * + flac->seekpoints = calloc(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) diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index 15afe221d..0d18783c2 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -313,7 +313,7 @@ static int parse_flv_var(demux_flv_t *this, if (!this->index || this->num_indices != num) { if (this->index) free(this->index); - this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + this->index = calloc(num, sizeof(flv_index_entry_t)); if (!this->index) return 0; this->num_indices = num; @@ -331,7 +331,7 @@ static int parse_flv_var(demux_flv_t *this, if (!this->index || this->num_indices != num) { if (this->index) free(this->index); - this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + this->index = calloc(num, sizeof(flv_index_entry_t)); if (!this->index) return 0; this->num_indices = num; diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 56759dd4b..c7af1c508 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -460,7 +460,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 = calloc (vbri->toc_entries + 1, sizeof (int)); if (!vbri->toc) { free (vbri); return NULL; diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 1be93abd9..695059c09 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -911,8 +911,8 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt elst atom (edit list atom): %d entries\n", trak->edit_list_count); - trak->edit_list_table = (edit_list_table_t *)xine_xmalloc( - trak->edit_list_count * sizeof(edit_list_table_t)); + trak->edit_list_table = (edit_list_table_t *)calloc( + trak->edit_list_count, sizeof(edit_list_table_t)); if (!trak->edit_list_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -947,7 +947,7 @@ 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 = calloc(trak->stsd_atoms_count, sizeof(properties_t)); if (!trak->stsd_atoms) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1345,8 +1345,8 @@ static qt_error parse_trak_atom (qt_trak *trak, /* allocate space and load table only if sample size is 0 */ if (trak->sample_size == 0) { - trak->sample_size_table = (unsigned int *)malloc( - trak->sample_size_count * sizeof(unsigned int)); + trak->sample_size_table = (unsigned int *)calloc( + trak->sample_size_count, sizeof(unsigned int)); if (!trak->sample_size_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1376,8 +1376,8 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stss atom (sample sync atom): %d sync samples\n", trak->sync_sample_count); - trak->sync_sample_table = (unsigned int *)malloc( - trak->sync_sample_count * sizeof(unsigned int)); + trak->sync_sample_table = (unsigned int *)calloc( + trak->sync_sample_count, sizeof(unsigned int)); if (!trak->sync_sample_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1405,8 +1405,8 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stco atom (32-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = (int64_t *)calloc( + trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1433,8 +1433,8 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt co64 atom (64-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = (int64_t *)calloc( + trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1464,8 +1464,8 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stsc atom (sample-to-chunk atom): %d entries\n", trak->sample_to_chunk_count); - trak->sample_to_chunk_table = (sample_to_chunk_table_t *)malloc( - trak->sample_to_chunk_count * sizeof(sample_to_chunk_table_t)); + trak->sample_to_chunk_table = (sample_to_chunk_table_t *)calloc( + trak->sample_to_chunk_count, sizeof(sample_to_chunk_table_t)); if (!trak->sample_to_chunk_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1499,8 +1499,8 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stts atom (time-to-sample atom): %d entries\n", trak->time_to_sample_count); - trak->time_to_sample_table = (time_to_sample_table_t *)malloc( - (trak->time_to_sample_count+1) * sizeof(time_to_sample_table_t)); + trak->time_to_sample_table = (time_to_sample_table_t *)calloc( + trak->time_to_sample_count+1, sizeof(time_to_sample_table_t)); if (!trak->time_to_sample_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1697,8 +1697,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * entries in the sample size table */ trak->frame_count = trak->sample_size_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = (qt_frame *)calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; trak->current_frame = 0; @@ -1710,7 +1709,7 @@ static qt_error build_frame_table(qt_trak *trak, pts_index_countdown = trak->time_to_sample_table[pts_index].count; - media_id_counts = xine_xmalloc(trak->stsd_atoms_count * sizeof(int)); + media_id_counts = calloc(trak->stsd_atoms_count, sizeof(int)); if (!media_id_counts) return QT_NO_MEMORY; memset(media_id_counts, 0, trak->stsd_atoms_count * sizeof(int)); @@ -1848,8 +1847,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * chunks */ trak->frame_count = trak->chunk_offset_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = (qt_frame *)calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index c5096b210..60075d750 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -233,7 +233,7 @@ static void real_parse_index(demux_real_t *this) { if(index && entries) /* Allocate memory for index */ - *index = xine_xmalloc(entries * sizeof(real_index_entry_t)); + *index = calloc(entries, sizeof(real_index_entry_t)); if(index && entries && *index) { /* Read index */ diff --git a/src/demuxers/demux_tta.c b/src/demuxers/demux_tta.c index f6eadd652..f0dd2612e 100644 --- a/src/demuxers/demux_tta.c +++ b/src/demuxers/demux_tta.c @@ -87,7 +87,7 @@ static int open_tta_file(demux_tta_t *this) { return 0; } - this->seektable = xine_xmalloc(sizeof(uint32_t)*this->totalframes); + this->seektable = calloc(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_vmd.c b/src/demuxers/demux_vmd.c index 8b0087417..416e86f39 100644 --- a/src/demuxers/demux_vmd.c +++ b/src/demuxers/demux_vmd.c @@ -168,7 +168,7 @@ static int open_vmd_file(demux_vmd_t *this) { return 0; } - this->frame_table = xine_xmalloc(this->frame_count * sizeof(vmd_frame_t)); + this->frame_table = calloc(this->frame_count, sizeof(vmd_frame_t)); current_offset = this->data_start = _X_LE_32(&vmd_header[20]); this->data_size = toc_offset - this->data_start; diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c index 1a839924d..b3dcb775f 100644 --- a/src/demuxers/demux_wc3movie.c +++ b/src/demuxers/demux_wc3movie.c @@ -378,7 +378,7 @@ 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 = calloc(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; @@ -387,7 +387,7 @@ static int open_mve_file(demux_mve_t *this) { this->input->seek(this->input, 12, SEEK_CUR); /* load the palette chunks */ - this->palettes = xine_xmalloc(this->number_of_shots * PALETTE_SIZE * + this->palettes = calloc(this->number_of_shots, PALETTE_SIZE * sizeof(palette_entry_t)); if (!this->shot_offsets || !this->palettes) { -- cgit v1.2.3 From b2602b679fa4f7a3d9d2ea8bfe8bc9298451ed60 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 28 Mar 2008 22:50:47 +0000 Subject: More checking for memory allocation failures. --- src/demuxers/demux_4xm.c | 2 +- src/demuxers/demux_avi.c | 10 ++++++++++ src/demuxers/demux_flac.c | 2 ++ src/demuxers/demux_iff.c | 10 +++++++++- src/demuxers/demux_ipmovie.c | 5 +++-- src/demuxers/demux_qt.c | 29 +++++++++++++++++++++++++++++ src/demuxers/demux_realaudio.c | 2 +- src/demuxers/demux_wav.c | 2 +- 8 files changed, 56 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_4xm.c b/src/demuxers/demux_4xm.c index 24aee1ac4..b06651456 100644 --- a/src/demuxers/demux_4xm.c +++ b/src/demuxers/demux_4xm.c @@ -159,7 +159,7 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) { /* read the whole header */ header_size = _X_LE_32(&preview[4]) - 4; header = xine_xmalloc(header_size); - if (fourxm->input->read(fourxm->input, header, header_size) != header_size) { + if (!header || fourxm->input->read(fourxm->input, header, header_size) != header_size) { free(header); return 0; } diff --git a/src/demuxers/demux_avi.c b/src/demuxers/demux_avi.c index 6bb0b289c..656e4662a 100644 --- a/src/demuxers/demux_avi.c +++ b/src/demuxers/demux_avi.c @@ -973,6 +973,10 @@ static avi_t *AVI_init(demux_avi_t *this) { xine_waveformatex *wavex; wavex = (xine_waveformatex *)malloc(n); + if (!wavex) { + this->AVI_errno = AVI_ERR_NO_MEM; + return 0; + } memcpy((void *)wavex, hdrl_data+i, n); _x_waveformatex_le2me( wavex ); @@ -1237,6 +1241,9 @@ static avi_t *AVI_init(demux_avi_t *this) { /* read from file */ chunk_start = en = malloc (AVI->video_superindex->aIndex[j].dwSize+hdrl_len); + if (!chunk_start) + ERR_EXIT(AVI_ERR_NO_MEM); + if (this->input->seek(this->input, AVI->video_superindex->aIndex[j].qwOffset, SEEK_SET) == (off_t)-1) { lprintf("cannot seek to 0x%" PRIx64 "\n", AVI->video_superindex->aIndex[j].qwOffset); free(chunk_start); @@ -1308,6 +1315,9 @@ static avi_t *AVI_init(demux_avi_t *this) { /* read from file */ chunk_start = en = malloc (audio->audio_superindex->aIndex[j].dwSize+hdrl_len); + if (!chunk_start) + ERR_EXIT(AVI_ERR_NO_MEM); + if (this->input->seek(this->input, audio->audio_superindex->aIndex[j].qwOffset, SEEK_SET) == (off_t)-1) { lprintf("cannot seek to 0x%" PRIx64 "\n", audio->audio_superindex->aIndex[j].qwOffset); free(chunk_start); diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index c3d547cdb..b4c5edb2d 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -166,6 +166,8 @@ static int open_flac_file(demux_flac_t *flac) { flac->seekpoint_count = block_length / FLAC_SEEKPOINT_SIZE; flac->seekpoints = calloc(flac->seekpoint_count, sizeof(flac_seekpoint_t)); + if (flac->seekpoint_count && !flac->seekpoints) + return 0; for (i = 0; i < flac->seekpoint_count; i++) { if (flac->input->read(flac->input, buffer, FLAC_SEEKPOINT_SIZE) != FLAC_SEEKPOINT_SIZE) return 0; diff --git a/src/demuxers/demux_iff.c b/src/demuxers/demux_iff.c index d914405db..0856eec1a 100644 --- a/src/demuxers/demux_iff.c +++ b/src/demuxers/demux_iff.c @@ -401,7 +401,7 @@ static int read_iff_chunk(demux_iff_t *this) { this->cmap_num = junk_size / PIC_SIZE_OF_COLOR_REGISTER; this->cmap = (ColorRegister *)xine_xmalloc(junk_size); this->video_send_palette = 1; - if (this->input->read(this->input, (char *)this->cmap, junk_size) != junk_size) + if (!this->cmap || this->input->read(this->input, (char *)this->cmap, junk_size) != junk_size) return 0; break; case IFF_GRAB_CHUNK: @@ -709,11 +709,19 @@ static int demux_iff_send_chunk(demux_plugin_t *this_gen) { /* load the whole chunk into the buffer */ if (this->audio_buffer_filled == 0) { if (this->audio_interleave_buffer_size > 0) + { this->audio_interleave_buffer = xine_xmalloc(this->audio_interleave_buffer_size); + if (!this->audio_interleave_buffer) + return this->status = DEMUX_FINISHED; + } if (this->audio_read_buffer_size > 0) + { this->audio_read_buffer = xine_xmalloc(this->audio_read_buffer_size); + if (!this->audio_read_buffer) + return this->status = DEMUX_FINISHED; + } if (this->audio_read_buffer) { if (this->input->read(this->input, this->audio_read_buffer, this->data_size) != this->data_size) { diff --git a/src/demuxers/demux_ipmovie.c b/src/demuxers/demux_ipmovie.c index cd21896c0..12640e662 100644 --- a/src/demuxers/demux_ipmovie.c +++ b/src/demuxers/demux_ipmovie.c @@ -283,9 +283,10 @@ static int process_ipmovie_chunk(demux_ipmovie_t *this) { this->bih.biWidth = _X_LE_16(&scratch[0]) * 8; this->bih.biHeight = _X_LE_16(&scratch[2]) * 8; /* set up staging area for decode map */ - this->decode_map_size = (this->bih.biWidth * this->bih.biHeight) / - (8 * 8) / 2; + this->decode_map_size = (this->bih.biWidth / 8) * (this->bih.biHeight / 8) / 2; this->decode_map = xine_xmalloc(this->decode_map_size); + if (!this->decode_map) + this->status = DEMUX_FINISHED; lprintf("video resolution: %d x %d\n", this->bih.biWidth, this->bih.biHeight); break; diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 695059c09..e28952b23 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -896,6 +896,11 @@ static qt_error parse_trak_atom (qt_trak *trak, current_atom_size = _X_BE_32(&trak_atom[i - 4]); current_atom = _X_BE_32(&trak_atom[i]); + if (current_atom_size > trak_atom_size - i) { + last_error = QT_NOT_A_VALID_FILE; + goto free_trak; + } + if (current_atom == TKHD_ATOM) { trak->flags = _X_BE_16(&trak_atom[i + 6]); } else if (current_atom == ELST_ATOM) { @@ -969,6 +974,10 @@ static qt_error parse_trak_atom (qt_trak *trak, trak->stsd_atoms[k].video.properties_atom_size = current_stsd_atom_size - 4; trak->stsd_atoms[k].video.properties_atom = xine_xmalloc(trak->stsd_atoms[k].video.properties_atom_size); + if (!trak->stsd_atoms[k].video.properties_atom) { + last_error = QT_NO_MEMORY; + goto free_trak; + } memcpy(trak->stsd_atoms[k].video.properties_atom, &trak_atom[atom_pos], trak->stsd_atoms[k].video.properties_atom_size); @@ -1108,6 +1117,10 @@ static qt_error parse_trak_atom (qt_trak *trak, trak->stsd_atoms[k].audio.properties_atom_size = current_stsd_atom_size - 4; trak->stsd_atoms[k].audio.properties_atom = xine_xmalloc(trak->stsd_atoms[k].audio.properties_atom_size); + if (!trak->stsd_atoms[k].audio.properties_atom) { + last_error = QT_NO_MEMORY; + goto free_trak; + } memcpy(trak->stsd_atoms[k].audio.properties_atom, &trak_atom[atom_pos], trak->stsd_atoms[k].audio.properties_atom_size); @@ -1224,6 +1237,10 @@ static qt_error parse_trak_atom (qt_trak *trak, trak->stsd_atoms[k].audio.properties_atom_size = 36; trak->stsd_atoms[k].audio.properties_atom = xine_xmalloc(trak->stsd_atoms[k].audio.properties_atom_size); + if (!trak->stsd_atoms[k].audio.properties_atom) { + last_error = QT_NO_MEMORY; + goto free_trak; + } memcpy(trak->stsd_atoms[k].audio.properties_atom, &trak_atom[atom_pos + 0x20], trak->stsd_atoms[k].audio.properties_atom_size); @@ -1245,6 +1262,10 @@ static qt_error parse_trak_atom (qt_trak *trak, (current_atom_size >= (0x4C + wave_size))) { trak->stsd_atoms[k].audio.wave_size = wave_size; trak->stsd_atoms[k].audio.wave = xine_xmalloc(wave_size); + if (!trak->stsd_atoms[k].audio.wave) { + last_error = QT_NO_MEMORY; + goto free_trak; + } memcpy(trak->stsd_atoms[k].audio.wave, &trak_atom[atom_pos + 0x4C], wave_size); _x_waveformatex_le2me(trak->stsd_atoms[k].audio.wave); @@ -1314,8 +1335,16 @@ static qt_error parse_trak_atom (qt_trak *trak, j += mp4_read_descr_len( &trak_atom[j], &len ); debug_atom_load(" decoder config is %d (0x%X) bytes long\n", len, len); + if (len > current_atom_size - (j - i)) { + last_error = QT_NOT_A_VALID_FILE; + goto free_trak; + } trak->decoder_config = realloc(trak->decoder_config, len); trak->decoder_config_len = len; + if (!trak->decoder_config) { + last_error = QT_NO_MEMORY; + goto free_trak; + } memcpy(trak->decoder_config,&trak_atom[j],len); } } diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c index 70c9b310a..b663912b8 100644 --- a/src/demuxers/demux_realaudio.c +++ b/src/demuxers/demux_realaudio.c @@ -103,7 +103,7 @@ static int open_ra_file(demux_ra_t *this) { /* allocate for and read header data */ this->header = xine_xmalloc(this->header_size); - if (_x_demux_read_header(this->input, this->header, this->header_size) != this->header_size) { + if (!this->header || _x_demux_read_header(this->input, this->header, this->header_size) != this->header_size) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_realaudio: unable to read header\n"); free(this->header); return 0; diff --git a/src/demuxers/demux_wav.c b/src/demuxers/demux_wav.c index f654a0f3e..eb9b9a6ed 100644 --- a/src/demuxers/demux_wav.c +++ b/src/demuxers/demux_wav.c @@ -131,7 +131,7 @@ static int open_wav_file(demux_wav_t *this) { this->input->seek(this->input, wave_pos, SEEK_SET); this->wave = xine_xmalloc( this->wave_size ); - if (this->input->read(this->input, (void *)this->wave, this->wave_size) != + if (!this->wave || this->input->read(this->input, (void *)this->wave, this->wave_size) != this->wave_size) { free (this->wave); return 0; -- cgit v1.2.3 From 30216c0016482506a11fa7f54d72d724e56fa5b3 Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Thu, 27 Mar 2008 17:27:12 +0200 Subject: read only full frames into buffer - otherwise decoder will lose trailing bytes for 24bit AIFF --- src/demuxers/demux_aiff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c index 3f2d0df11..f520219fa 100644 --- a/src/demuxers/demux_aiff.c +++ b/src/demuxers/demux_aiff.c @@ -150,7 +150,9 @@ static int open_aiff_file(demux_aiff_t *this) { (this->audio_bits / 8); this->running_time = (this->audio_frames / this->audio_sample_rate) * 1000; - this->audio_block_align = PCM_BLOCK_ALIGN; + /* we should send only complete frames to decoder, as it + * doesn't handle underconsumption yet */ + this->audio_block_align = PCM_BLOCK_ALIGN - PCM_BLOCK_ALIGN % (this->audio_bits / 8 * this->audio_channels); break; -- cgit v1.2.3 From aba07be1265b56cc777c17e09cccebe1121ef697 Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Fri, 28 Mar 2008 15:52:34 +0200 Subject: AIFF comment chunks are word-aligned, so we should seek extra byte for them --- src/demuxers/demux_aiff.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c index f520219fa..b30b74910 100644 --- a/src/demuxers/demux_aiff.c +++ b/src/demuxers/demux_aiff.c @@ -46,6 +46,10 @@ #define COMM_TAG FOURCC_TAG('C', 'O', 'M', 'M') #define SSND_TAG FOURCC_TAG('S', 'S', 'N', 'D') #define APCM_TAG FOURCC_TAG('A', 'P', 'C', 'M') +#define NAME_TAG FOURCC_TAG('N', 'A', 'M', 'E') +#define AUTH_TAG FOURCC_TAG('A', 'U', 'T', 'H') +#define COPY_TAG FOURCC_TAG('(', 'c', ')', ' ') +#define ANNO_TAG FOURCC_TAG('A', 'N', 'N', 'O') #define PREAMBLE_SIZE 8 #define AIFF_SIGNATURE_SIZE 12 @@ -157,6 +161,11 @@ static int open_aiff_file(demux_aiff_t *this) { break; } else { + /* if chunk contains metadata, it will be word-aligned (as seen at sox and ffmpeg) */ + if ( ((chunk_type == NAME_TAG) || (chunk_type==AUTH_TAG) || + (chunk_type == COPY_TAG) || (chunk_type==ANNO_TAG)) && (chunk_size&1)) + chunk_size++; + /* unrecognized; skip it */ this->input->seek(this->input, chunk_size, SEEK_CUR); } -- cgit v1.2.3 From 8fd1e52ecdd12b6e8b6ad920e47702201aeafb4b Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Thu, 27 Mar 2008 17:29:00 +0200 Subject: take into account CPU endianness when converting 24bit=>16bit samples --- src/libxineadec/xine_lpcm_decoder.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libxineadec/xine_lpcm_decoder.c b/src/libxineadec/xine_lpcm_decoder.c index 8d8f23a05..9587da6e8 100644 --- a/src/libxineadec/xine_lpcm_decoder.c +++ b/src/libxineadec/xine_lpcm_decoder.c @@ -189,11 +189,23 @@ static void lpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { while (n >= 0) { if ( stream_be ) { - *d++ = s[0]; - *d++ = s[1]; + if ( stream_be == this->cpu_be ) { + *d++ = s[0]; + *d++ = s[1]; + } else { + *d++ = s[1]; + *d++ = s[0]; + } } else { - *d++ = s[1]; - *d++ = s[2]; + if ( stream_be == this->cpu_be ) { + *d++ = s[1]; + *d++ = s[2]; + } + else + { + *d++ = s[2]; + *d++ = s[1]; + } } s += 3; -- cgit v1.2.3 From 7d7b7eb2f71df2e90e4100348993966e5c26d022 Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Fri, 28 Mar 2008 17:00:38 +0200 Subject: fix overreading from input buffer and report lost bytes in lpcm decoder --- src/libxineadec/xine_lpcm_decoder.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libxineadec/xine_lpcm_decoder.c b/src/libxineadec/xine_lpcm_decoder.c index 9587da6e8..eeed7ba35 100644 --- a/src/libxineadec/xine_lpcm_decoder.c +++ b/src/libxineadec/xine_lpcm_decoder.c @@ -187,7 +187,7 @@ static void lpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { uint8_t *d = (uint8_t *)audio_buffer->mem; int n = buf->size; - while (n >= 0) { + while (n >= 3) { if ( stream_be ) { if ( stream_be == this->cpu_be ) { *d++ = s[0]; @@ -211,6 +211,10 @@ static void lpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { s += 3; n -= 3; } + + if ( (d - (uint8_t*)audio_buffer->mem)/2*3 < buf->size ) + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "lpcm_decoder: lost %i bytes\n", (int)(buf->size - (d - (uint8_t*)audio_buffer->mem))/2*3); + } else { memcpy (audio_buffer->mem, sample_buffer, buf->size); } -- cgit v1.2.3 From fd4cb7f8687ded5d128cd8a63df99d69201f1b9a Mon Sep 17 00:00:00 2001 From: Kirill Belokurov Date: Wed, 26 Mar 2008 18:01:20 +0200 Subject: calculate AIFF files samplerate from 80-bit float, fixes wrong playback of some AIFF files --- src/demuxers/demux_aiff.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c index b30b74910..8a2811ac6 100644 --- a/src/demuxers/demux_aiff.c +++ b/src/demuxers/demux_aiff.c @@ -84,6 +84,24 @@ typedef struct { demux_class_t demux_class; } demux_aiff_class_t; +/* converts IEEE 80bit extended into int, based on FFMPEG code */ +int extended_to_int(const unsigned char p[10]) +{ + uint64_t m = 0; + int e, i; + + for (i = 0; i < 8; i++) + m = (m<<8) + p[2+i];; + e = (((int)p[0]&0x7f)<<8) | p[1]; + if (e == 0x7fff && m) + return 0.0/0.0; + e -= 16383 + 63; + + if (p[0]&0x80) + m= -m; + return (int) ldexp(m, e); +} + /* returns 1 if the AIFF file was opened successfully, 0 otherwise */ static int open_aiff_file(demux_aiff_t *this) { @@ -91,6 +109,7 @@ static int open_aiff_file(demux_aiff_t *this) { unsigned char preamble[PREAMBLE_SIZE]; unsigned int chunk_type; unsigned int chunk_size; + unsigned char extended_sample_rate[10]; if (_x_demux_read_header(this->input, signature, AIFF_SIGNATURE_SIZE) != AIFF_SIGNATURE_SIZE) return 0; @@ -139,7 +158,8 @@ static int open_aiff_file(demux_aiff_t *this) { this->audio_channels = _X_BE_16(&buffer[0]); this->audio_frames = _X_BE_32(&buffer[2]); this->audio_bits = _X_BE_16(&buffer[6]); - this->audio_sample_rate = _X_BE_16(&buffer[0x0A]); + memcpy(&extended_sample_rate, &buffer[8], sizeof(extended_sample_rate)); + this->audio_sample_rate = extended_to_int(extended_sample_rate); this->audio_bytes_per_second = this->audio_channels * (this->audio_bits / 8) * this->audio_sample_rate; -- cgit v1.2.3 From 1bedd052b17aab0fc6b1b85a727207648908095b Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 26 Mar 2008 18:54:55 +0000 Subject: Be more careful with malloc(x+1), particularly on 32-bit. --- src/demuxers/demux_matroska.c | 14 ++++---------- src/demuxers/ebml.c | 25 +++++++++++++++++-------- src/demuxers/ebml.h | 2 ++ 3 files changed, 23 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 63b6ea3c8..7643a2cb4 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1179,13 +1179,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { break; case MATROSKA_ID_TR_CODECID: { - char *codec_id = malloc (elem.len + 1); + char *codec_id = ebml_alloc_read_ascii (ebml, &elem); lprintf("CodecID\n"); - if (!ebml_read_ascii(ebml, &elem, codec_id)) { - free(codec_id); + if (!codec_id) return 0; - } - codec_id[elem.len] = '\0'; track->codec_id = codec_id; } break; @@ -1203,13 +1200,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { break; case MATROSKA_ID_TR_LANGUAGE: { - char *language = malloc (elem.len + 1); + char *language = ebml_alloc_read_ascii (ebml, &elem); lprintf("Language\n"); - if (!ebml_read_ascii(ebml, &elem, language)) { - free(language); + if (!language) return 0; - } - language[elem.len] = '\0'; track->language = language; } break; diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index cc8173c26..0c633643f 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -318,6 +318,22 @@ int ebml_read_utf8 (ebml_parser_t *ebml, ebml_elem_t *elem, char *str) { return ebml_read_ascii (ebml, elem, str); } +char *ebml_alloc_read_ascii (ebml_parser_t *ebml, ebml_elem_t *elem) +{ + char *text; + if (elem->len >= 4096) + return NULL; + text = malloc(elem->len + 1); + if (text) + { + text[elem->len] = '\0'; + if (ebml_read_ascii (ebml, &elem, text)) + return text; + free (text); + } + return NULL; +} + int ebml_read_date (ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *date) { return ebml_read_sint (ebml, elem, date); } @@ -423,17 +439,10 @@ int ebml_check_header(ebml_parser_t *ebml) { } case EBML_ID_DOCTYPE: { - char *text = malloc(elem.len + 1); + char *text = ebml_alloc_read_ascii (ebml, &elem); if (!text) return 0; - text[elem.len] = '\0'; - if (!ebml_read_ascii (ebml, &elem, text)) - { - free (text); - return 0; - } - lprintf("doctype: %s\n", text); if (ebml->doctype) free (ebml->doctype); diff --git a/src/demuxers/ebml.h b/src/demuxers/ebml.h index 35078c502..a38515544 100644 --- a/src/demuxers/ebml.h +++ b/src/demuxers/ebml.h @@ -91,6 +91,8 @@ int ebml_read_ascii(ebml_parser_t *ebml, ebml_elem_t *elem, char *str); int ebml_read_utf8(ebml_parser_t *ebml, ebml_elem_t *elem, char *str); +char *ebml_alloc_read_ascii(ebml_parser_t *ebml, ebml_elem_t *elem); + int ebml_read_date(ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *date); int ebml_read_master(ebml_parser_t *ebml, ebml_elem_t *elem); -- cgit v1.2.3 From 3350b8b761d9cd0052d280cf89848a58989c3b1b Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 30 Mar 2008 19:48:58 +0100 Subject: Add video/x-matroska. --- src/demuxers/demux_matroska.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 7643a2cb4..d081caf61 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -2915,7 +2915,8 @@ static const char *get_extensions (demux_class_t *this_gen) { static const char *get_mimetypes (demux_class_t *this_gen) { - return "video/mkv: mkv: matroska;"; + return "video/mkv: mkv: matroska;" + "video/x-matroska: mkv: matroska;"; } -- cgit v1.2.3 From 7dab7b45bb3ac2e16b4a5eb1c8ed110dcd239246 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 31 Mar 2008 16:08:23 +0100 Subject: Revert a change which broke Quicktime atom parsing. --- src/demuxers/demux_qt.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index e28952b23..851b0aef5 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -896,11 +896,6 @@ static qt_error parse_trak_atom (qt_trak *trak, current_atom_size = _X_BE_32(&trak_atom[i - 4]); current_atom = _X_BE_32(&trak_atom[i]); - if (current_atom_size > trak_atom_size - i) { - last_error = QT_NOT_A_VALID_FILE; - goto free_trak; - } - if (current_atom == TKHD_ATOM) { trak->flags = _X_BE_16(&trak_atom[i + 6]); } else if (current_atom == ELST_ATOM) { -- cgit v1.2.3 From 55c8e3a5c01ff089531ab5f73f43584a12ca9edd Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 31 Mar 2008 21:13:31 +0100 Subject: Correct the wavpack demuxer's MIME type data. --- src/combined/demux_wavpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/demux_wavpack.c b/src/combined/demux_wavpack.c index a79f70627..a9b20e5f9 100644 --- a/src/combined/demux_wavpack.c +++ b/src/combined/demux_wavpack.c @@ -391,7 +391,7 @@ static const char *get_extensions (demux_class_t *const this_gen) { } static const char *get_mimetypes (demux_class_t *const this_gen) { - return "audio/x-wavpack"; + return "audio/x-wavpack: wv,wvp: WavPack audio;"; } static void class_dispose (demux_class_t *const this_gen) { -- cgit v1.2.3 From 577d6eca166c0f0dce00d4a0f22eabb7025f61a8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Apr 2008 14:05:56 +0200 Subject: Updated PulseAudio driver It's basically a rework of the PulseAudio driver, fixing all the inherent races (and thus stability issues), adding proper surround sound support, support for proper muting and pause/resume. It also gets rid of all usleep() loops to make sure we don't wakeup more often than we need to. Also does a couple of other minor cleanups. This also increases the autoprobe priority to 12, above ALSA, to make sure that the Pulse plugin is preferred over ALSA if both are available. This is because we want to make sure that Xine-on-PA is preferred over Xine-on-ALSA-on-PA. --- src/audio_out/audio_pulse_out.c | 680 ++++++++++++++++++++++++++-------------- 1 file changed, 440 insertions(+), 240 deletions(-) (limited to 'src') diff --git a/src/audio_out/audio_pulse_out.c b/src/audio_out/audio_pulse_out.c index 2811bbdbc..f5ade655f 100644 --- a/src/audio_out/audio_pulse_out.c +++ b/src/audio_out/audio_pulse_out.c @@ -1,28 +1,28 @@ -/* - * Copyright (C) 2000-2007 the xine project - * +/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + * Copyright (C) 2000-2008 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 * - * ao plugin for pulseaudio (rename of polypaudio): + * ao plugin for PulseAudio: * http://0pointer.de/lennart/projects/pulsaudio/ * - * originally written for polypaudio simple api. Lennart then suggested - * using the async api for better control (such as volume), therefore, a lot - * of this code comes from Lennart's patch to mplayer. + * Diego Petteno, Lennart Poettering */ #ifdef HAVE_CONFIG_H @@ -48,9 +48,6 @@ #define GAP_TOLERANCE AO_MAX_GAP -/* CHECKME: should this be conditional on autotools? */ -extern const char *__progname; - typedef struct { audio_driver_class_t driver_class; xine_t *xine; @@ -69,9 +66,8 @@ typedef struct pulse_driver_s { char *sink; /*< The sink to connect to */ struct pa_stream *stream; /*< Pulseaudio playback stream object */ - pthread_mutex_t info_mutex; /**< Mutex for info callback signaling */ - pa_volume_t swvolume; + int muted; pa_cvolume cvolume; int capabilities; @@ -82,69 +78,119 @@ typedef struct pulse_driver_s { uint32_t bits_per_sample; uint32_t bytes_per_frame; - uint32_t frames_written; - } pulse_driver_t; /** - * @brief Callback function called when a stream operation succeed - * @param stream Stream which operation has succeeded - * @param success The success value for the operation (ignored) - * @param this_Gen pulse_driver_t pointer for the PulseAudio output - * instance. + * @brief Callback function called when the state of the context is changed + * @param c Context which changed status + * @param this_gen pulse_class_t pointer for the PulseAudio output class */ -static void __xine_pa_stream_success_callback(pa_stream *const stream, const int success, - void *const mutex_gen) +static void __xine_pa_context_state_callback(pa_context *c, void *this_gen) { - pthread_mutex_t *const completion_mutex = (pthread_mutex_t*)mutex_gen; + pulse_class_t * this = (pulse_class_t*) this_gen; + + switch (pa_context_get_state(c)) { - pthread_mutex_unlock(completion_mutex); + case PA_CONTEXT_READY: + case PA_CONTEXT_TERMINATED: + case PA_CONTEXT_FAILED: + pa_threaded_mainloop_signal(this->mainloop, 0); + break; + + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_UNCONNECTED: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + } } /** - * @brief Callback function called when the state of the context is changed - * @param ctx Context which operation has succeeded + * @brief Callback function called when the state of the stream is changed + * @param s Stream that changed status * @param this_gen pulse_driver_t pointer for the PulseAudio output * instance. */ -static void __xine_pa_context_status_callback(pa_context *const ctx, void *const this_gen) +static void __xine_pa_stream_state_callback(pa_stream *s, void *this_gen) { - pulse_driver_t *const this = (pulse_driver_t*)this_gen; - - switch (pa_context_get_state(ctx)) { - case PA_CONTEXT_READY: - case PA_CONTEXT_TERMINATED: - case PA_CONTEXT_FAILED: - pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); - break; - - case PA_CONTEXT_CONNECTING: - case PA_CONTEXT_UNCONNECTED: - case PA_CONTEXT_AUTHORIZING: - case PA_CONTEXT_SETTING_NAME: - break; + pulse_driver_t * this = (pulse_driver_t*) this_gen; + + switch (pa_stream_get_state(s)) { + + case PA_STREAM_READY: + case PA_STREAM_TERMINATED: + case PA_STREAM_FAILED: + pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); + break; + + case PA_STREAM_UNCONNECTED: + case PA_STREAM_CREATING: + break; } } /** - * @brief Callback function called when a context operation succeed + * @brief Callback function called when PA asks for more audio data. + * @param s Stream on which data is requested + * @param nbytes the number of bytes PA requested + * @param this_gen pulse_driver_t pointer for the PulseAudio output + * instance. + */ +static void __xine_pa_stream_request_callback(pa_stream *s, size_t nbytes, void *this_gen) +{ + pulse_driver_t * this = (pulse_driver_t*) this_gen; + + pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); +} + +/** + * @brief Callback function called when PA notifies about something + * @param s Stream on which the notification happened + * @param this_gen pulse_driver_t pointer for the PulseAudio output + * instance. + */ +static void __xine_pa_stream_notify_callback(pa_stream *s, void *this_gen) +{ + pulse_driver_t * this = (pulse_driver_t*) this_gen; + + pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); +} + +/** + * @brief Callback function called when PA completed an operation * @param ctx Context which operation has succeeded - * @param success The success value for the operation (ignored) + * @param nbytes the number of bytes PA requested * @param this_gen pulse_driver_t pointer for the PulseAudio output * instance. */ -static void __xine_pa_context_success_callback(pa_context *const ctx, const int success, - void *const this_gen) +static void __xine_pa_stream_success_callback(pa_stream *s, int success, void *this_gen) { - pulse_driver_t *const this = (pulse_driver_t*)this_gen; + pulse_driver_t * this = (pulse_driver_t*) this_gen; - _x_assert(ctx); _x_assert(this); - _x_assert(ctx == this->pa_class->context); + if (!success) + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: stream operation failed: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); } +/** + * @brief Callback function called when PA completed an operation + * @param c Context on which operation has succeeded + * @param nbytes the number of bytes PA requested + * @param this_gen pulse_driver_t pointer for the PulseAudio output + * instance. + */ +static void __xine_pa_context_success_callback(pa_context *c, int success, void *this_gen) +{ + pulse_class_t *this = (pulse_class_t*) this_gen; + + if (!success) + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: context operation failed: %s\n", pa_strerror(pa_context_errno(this->context))); + + pa_threaded_mainloop_signal(this->mainloop, 0); +} + /** * @brief Callback function called when the information on the * context's sink is retrieved. @@ -156,8 +202,8 @@ static void __xine_pa_context_success_callback(pa_context *const ctx, const int * This function saves the volume field of the passed structure to the * @c cvolume variable of the output instance. */ -static void __xine_pa_sink_info_callback(pa_context *const ctx, const pa_sink_input_info *const info, - const int is_last, void *const userdata) { +static void __xine_pa_sink_info_callback(pa_context *c, const pa_sink_input_info *info, + int is_last, void *userdata) { pulse_driver_t *const this = (pulse_driver_t *) userdata; @@ -171,36 +217,43 @@ static void __xine_pa_sink_info_callback(pa_context *const ctx, const pa_sink_in return; this->cvolume = info->volume; - - pthread_mutex_unlock(&this->info_mutex); + this->swvolume = pa_sw_volume_to_linear(pa_cvolume_avg(&info->volume)); + this->muted = info->mute; } /* * open the audio device for writing to */ static int ao_pulse_open(ao_driver_t *this_gen, - uint32_t bits, uint32_t rate, int mode) + uint32_t bits, uint32_t rate, int mode) { pulse_driver_t *this = (pulse_driver_t *) this_gen; - struct pa_sample_spec ss; - struct pa_buffer_attr a; - pa_stream_state_t streamstate; + pa_sample_spec ss; + pa_channel_map cm; + int r; xprintf (this->xine, XINE_VERBOSITY_DEBUG, - "audio_pulse_out: ao_open bits=%d rate=%d, mode=%d\n", bits, rate, mode); + "audio_pulse_out: ao_open bits=%d rate=%d, mode=%d\n", bits, rate, mode); if ( (mode & this->capabilities) == 0 ) { xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: unsupported mode %08x\n", mode); return 0; } + pa_threaded_mainloop_lock(this->pa_class->mainloop); + if (this->stream) { - if ( mode == this->mode && rate == this->sample_rate && - bits == this->bits_per_sample ) + if (mode == this->mode && rate == this->sample_rate && + bits == this->bits_per_sample) { + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); return this->sample_rate; + } - this_gen->close(this_gen); + pa_stream_disconnect(this->stream); + pa_stream_unref(this->stream); + this->stream = NULL; } this->mode = mode; @@ -221,6 +274,8 @@ static int ao_pulse_open(ao_driver_t *this_gen, case 32: ss.format = PA_SAMPLE_FLOAT32NE; break; + default: + _x_assert(!"Should not be reached"); } if (!pa_sample_spec_valid(&ss)) { @@ -228,70 +283,125 @@ static int ao_pulse_open(ao_driver_t *this_gen, goto fail; } - if ( this->pa_class->context && pa_context_get_state(this->pa_class->context) > PA_CONTEXT_READY ) { + cm.channels = ss.channels; + + switch (mode) { + case AO_CAP_MODE_MONO: + cm.map[0] = PA_CHANNEL_POSITION_MONO; + _x_assert(cm.channels == 1); + break; + + case AO_CAP_MODE_STEREO: + cm.map[0] = PA_CHANNEL_POSITION_FRONT_LEFT; + cm.map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT; + _x_assert(cm.channels == 2); + break; + + case AO_CAP_MODE_4CHANNEL: + cm.map[0] = PA_CHANNEL_POSITION_FRONT_LEFT; + cm.map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT; + cm.map[2] = PA_CHANNEL_POSITION_REAR_LEFT; + cm.map[3] = PA_CHANNEL_POSITION_REAR_RIGHT; + _x_assert(cm.channels == 4); + break; + + case AO_CAP_MODE_4_1CHANNEL: + case AO_CAP_MODE_5CHANNEL: + case AO_CAP_MODE_5_1CHANNEL: + cm.map[0] = PA_CHANNEL_POSITION_FRONT_LEFT; + cm.map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT; + cm.map[2] = PA_CHANNEL_POSITION_REAR_LEFT; + cm.map[3] = PA_CHANNEL_POSITION_REAR_RIGHT; + cm.map[4] = PA_CHANNEL_POSITION_FRONT_CENTER; + cm.map[5] = PA_CHANNEL_POSITION_LFE; + cm.channels = 6; + break; + default: + _x_assert(!"Should not be reached"); + } + + if (!pa_channel_map_valid(&cm)) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: Invalid channel map\n"); + goto fail; + } + + if ( this->pa_class->context && (pa_context_get_state(this->pa_class->context) == PA_CONTEXT_FAILED || + pa_context_get_state(this->pa_class->context) == PA_CONTEXT_TERMINATED)) { pa_context_unref(this->pa_class->context); this->pa_class->context = NULL; } - if ( this->pa_class->context == NULL ) { - this->pa_class->context = pa_context_new(pa_threaded_mainloop_get_api(this->pa_class->mainloop), - __progname); - } + if (!this->pa_class->context) { + char fn[PATH_MAX], *p; - pa_context_ref(this->pa_class->context); + if (pa_get_binary_name(fn, sizeof(fn))) + p = pa_path_get_filename(fn); + else + p = "Xine"; - if ( pa_context_get_state(this->pa_class->context) == PA_CONTEXT_UNCONNECTED ) { - int ret; + this->pa_class->context = pa_context_new(pa_threaded_mainloop_get_api(this->pa_class->mainloop), p); + _x_assert(this->pa_class->context); - pa_threaded_mainloop_lock(this->pa_class->mainloop); - ret = pa_context_connect(this->pa_class->context, this->host, 1, NULL); - if ( ret < 0 ) - goto fail_unlock; + pa_context_set_state_callback(this->pa_class->context, __xine_pa_context_state_callback, this->pa_class); + } - pa_context_set_state_callback(this->pa_class->context, __xine_pa_context_status_callback, this); + if (pa_context_get_state(this->pa_class->context) == PA_CONTEXT_UNCONNECTED) { - pa_threaded_mainloop_wait(this->pa_class->mainloop); - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + if (pa_context_connect(this->pa_class->context, this->host, 0, NULL) < 0) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object\n"); + goto fail; + } } - if (pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY) { - xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: Failed to connect to server: %s\n", - pa_strerror(pa_context_errno(this->pa_class->context))); - goto fail; + for (;;) { + pa_context_state_t state = pa_context_get_state(this->pa_class->context); + + if (state == PA_CONTEXT_FAILED || state == PA_CONTEXT_TERMINATED) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); + goto fail; + } + + if (state == PA_CONTEXT_READY) + break; + + pa_threaded_mainloop_wait(this->pa_class->mainloop); } - this->stream = pa_stream_new(this->pa_class->context, "audio stream", &ss, NULL); + _x_assert(!this->stream); + this->stream = pa_stream_new(this->pa_class->context, "Audio Stream", &ss, &cm); _x_assert(this->stream); - a.maxlength = pa_bytes_per_second(&ss)*1; - a.tlength = a.maxlength*9/10; - a.prebuf = a.tlength/2; - a.minreq = a.tlength/10; + pa_stream_set_state_callback(this->stream, __xine_pa_stream_state_callback, this); + pa_stream_set_write_callback(this->stream, __xine_pa_stream_request_callback, this); + pa_stream_set_latency_update_callback(this->stream, __xine_pa_stream_notify_callback, this); - pa_stream_connect_playback(this->stream, this->sink, &a, - PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, + r = pa_stream_connect_playback(this->stream, this->sink, NULL, + PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL); - do { - xine_usec_sleep (100); + for (;;) { + pa_context_state_t cstate = pa_context_get_state(this->pa_class->context); + pa_stream_state_t sstate = pa_stream_get_state(this->stream); - streamstate = pa_stream_get_state(this->stream); - } while (streamstate < PA_STREAM_READY); - - if (streamstate != PA_STREAM_READY) { - xprintf (this->xine, XINE_VERBOSITY_LOG, "audio_pulse_out: Failed to connect to server: %s\n", - pa_strerror(pa_context_errno(this->pa_class->context))); - goto fail; + if (cstate == PA_CONTEXT_FAILED || cstate == PA_CONTEXT_TERMINATED || + sstate == PA_STREAM_FAILED || sstate == PA_STREAM_TERMINATED) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); + goto fail; + } + + if (sstate == PA_STREAM_READY) + break; + + pa_threaded_mainloop_wait(this->pa_class->mainloop); } - this->frames_written = 0; - this->ao_driver.set_property(this, AO_PROP_PCM_VOL, 100); + pa_threaded_mainloop_unlock(this->pa_class->mainloop); return this->sample_rate; - fail_unlock: - pa_threaded_mainloop_unlock(this->pa_class->mainloop); fail: + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); this_gen->close(this_gen); return 0; } @@ -319,189 +429,268 @@ static int ao_pulse_write(ao_driver_t *this_gen, int16_t *data, { pulse_driver_t *this = (pulse_driver_t *) this_gen; size_t size = num_frames * this->bytes_per_frame; - int ret = 0; - - if ( !this->stream || !this->pa_class->context) - return -1; + int ret = -1; + size_t done = 0; - switch( pa_stream_get_state(this->stream) ) { - case PA_STREAM_READY: - while (size > 0) { - size_t l; + pa_threaded_mainloop_lock(this->pa_class->mainloop); - while (!(l = pa_stream_writable_size(this->stream))) { - xine_usec_sleep (10000); - } + while (size > 0) { + size_t l; - if (l > size) - l = size; - - pa_stream_write(this->stream, data, l, NULL, 0, PA_SEEK_RELATIVE); - data = (int16_t *) ((uint8_t*) data + l); - size -= l; - } + for (;;) { - this->frames_written += num_frames; + if (!this->stream || + !this->pa_class->context || + pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + pa_stream_get_state(this->stream) != PA_STREAM_READY) + goto finish; - if (pa_stream_get_state(this->stream) == PA_STREAM_READY) - ret = 1; + if ((l = pa_stream_writable_size(this->stream)) == (size_t) -1) + goto finish; - break; + if (l > 0) + break; + + pa_threaded_mainloop_wait(this->pa_class->mainloop); + } + + if (l > size) + l = size; + + pa_stream_write(this->stream, data, l, NULL, 0, PA_SEEK_RELATIVE); + data = (int16_t *) ((uint8_t*) data + l); + size -= l; + done += l; } + ret = done; + +finish: + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); + +/* fprintf(stderr, "write-out\n"); */ + return ret; -} +} static int ao_pulse_delay (ao_driver_t *this_gen) { pulse_driver_t *this = (pulse_driver_t *) this_gen; - pa_usec_t latency = 0; - unsigned int delay_frames; + int ret = 0; - if ( ! this->stream ) return this->frames_written; +/* fprintf(stderr, "delay-in\n"); */ - if (pa_stream_get_latency(this->stream, &latency, NULL) < 0) { - pa_context_unref(this->pa_class->context); - this->pa_class->context = NULL; + pa_threaded_mainloop_lock(this->pa_class->mainloop); - pa_stream_disconnect(this->stream); - pa_stream_unref(this->stream); - this->stream = NULL; + for (;;) { + pa_usec_t latency = 0; - return 0; + if (!this->stream || + !this->pa_class->context || + pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + pa_stream_get_state(this->stream) != PA_STREAM_READY) + goto finish; + + if (pa_stream_get_latency(this->stream, &latency, NULL) >= 0) { + ret = (int) ((latency * this->sample_rate) / 1000000); + goto finish; + } + + if (pa_context_errno(this->pa_class->context) != PA_ERR_NODATA) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to query latency: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); + goto finish; + } + + pa_threaded_mainloop_wait(this->pa_class->mainloop); } - /* convert latency (us) to frame units. */ - delay_frames = (int)(latency * this->sample_rate / 1000000); +finish: + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); - if( delay_frames > this->frames_written ) - return this->frames_written; - else - return delay_frames; + return ret; } static void ao_pulse_close(ao_driver_t *this_gen) { pulse_driver_t *this = (pulse_driver_t *) this_gen; - - if (this->stream) { - if (pa_stream_get_state(this->stream) == PA_STREAM_READY) { - pthread_mutex_t completion_callback = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&completion_callback); - pa_stream_drain(this->stream, __xine_pa_stream_success_callback, &completion_callback); - pthread_mutex_lock(&completion_callback); - pthread_mutex_destroy(&completion_callback); - } + pa_threaded_mainloop_lock(this->pa_class->mainloop); + if (this->stream) { pa_stream_disconnect(this->stream); pa_stream_unref(this->stream); this->stream = NULL; - - pa_context_unref(this->pa_class->context); } + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); } static uint32_t ao_pulse_get_capabilities (ao_driver_t *this_gen) { pulse_driver_t *this = (pulse_driver_t *) this_gen; + return this->capabilities; } -static void ao_pulse_exit(ao_driver_t *this_gen) -{ +static void ao_pulse_exit(ao_driver_t *this_gen) { pulse_driver_t *this = (pulse_driver_t *) this_gen; + ao_pulse_close(this_gen); + free (this); } +static int wait_for_operation(pulse_driver_t *this, pa_operation *o) { + + for (;;) { + + if (!this->stream || + !this->pa_class->context || + pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + pa_stream_get_state(this->stream) != PA_STREAM_READY) + return -1; + + if (pa_operation_get_state(o) != PA_OPERATION_RUNNING) + return 0; + + pa_threaded_mainloop_wait(this->pa_class->mainloop); + } +} + static int ao_pulse_get_property (ao_driver_t *this_gen, int property) { pulse_driver_t *this = (pulse_driver_t *) this_gen; int result = 0; + pa_operation *o = NULL; - if ( ! this->stream || ! this->pa_class->context ) + pa_threaded_mainloop_lock(this->pa_class->mainloop); + + if (!this->stream || + !this->pa_class->context || + pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + pa_stream_get_state(this->stream) != PA_STREAM_READY) { + pa_threaded_mainloop_unlock(this->pa_class->mainloop); return 0; + } switch(property) { - case AO_PROP_PCM_VOL: - case AO_PROP_MIXER_VOL: - { - pthread_mutex_lock(&this->info_mutex); - pa_operation *o = pa_context_get_sink_input_info(this->pa_class->context, - pa_stream_get_index(this->stream), - __xine_pa_sink_info_callback, this); - if ( ! o ) return 0; - pthread_mutex_lock(&this->info_mutex); pthread_mutex_unlock(&this->info_mutex); - - result = (pa_sw_volume_to_linear(this->swvolume)*100); - } - break; - case AO_PROP_MUTE_VOL: - result = pa_cvolume_is_muted(&this->cvolume); - break; + case AO_PROP_MUTE_VOL: + case AO_PROP_PCM_VOL: + case AO_PROP_MIXER_VOL: + + o = pa_context_get_sink_input_info(this->pa_class->context, pa_stream_get_index(this->stream), + __xine_pa_sink_info_callback, this); + + break; + } + + if (o) { + wait_for_operation(this, o); + pa_operation_unref(o); } - + + switch(property) { + + case AO_PROP_MUTE_VOL: + result = this->muted; + break; + + case AO_PROP_PCM_VOL: + case AO_PROP_MIXER_VOL: + result = (int) (pa_sw_volume_to_linear(this->swvolume)*100); + break; + } + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); + return result; } static int ao_pulse_set_property (ao_driver_t *this_gen, int property, int value) { pulse_driver_t *this = (pulse_driver_t *) this_gen; int result = ~value; + pa_operation *o = NULL; - if ( ! this->stream || ! this->pa_class->context ) - return result; + pa_threaded_mainloop_lock(this->pa_class->mainloop); + + if (!this->stream || + !this->pa_class->context || + pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + pa_stream_get_state(this->stream) != PA_STREAM_READY) { + pa_threaded_mainloop_unlock(this->pa_class->mainloop); + return 0; + } switch(property) { - case AO_PROP_PCM_VOL: - case AO_PROP_MIXER_VOL: - this->swvolume = pa_sw_volume_from_linear((double)value/100.0); - pa_cvolume_set(&this->cvolume, pa_stream_get_sample_spec(this->stream)->channels, this->swvolume); + case AO_PROP_PCM_VOL: + case AO_PROP_MIXER_VOL: - pa_context_set_sink_input_volume(this->pa_class->context, pa_stream_get_index(this->stream), - &this->cvolume, __xine_pa_context_success_callback, this); + this->swvolume = pa_sw_volume_from_linear((double)value/100.0); + pa_cvolume_set(&this->cvolume, pa_stream_get_sample_spec(this->stream)->channels, this->swvolume); - result = value; - break; + o = pa_context_set_sink_input_volume(this->pa_class->context, pa_stream_get_index(this->stream), + &this->cvolume, __xine_pa_context_success_callback, this->pa_class); - case AO_PROP_MUTE_VOL: - if ( value ) - pa_cvolume_mute(&this->cvolume, pa_stream_get_sample_spec(this->stream)->channels); - else - pa_cvolume_set(&this->cvolume, pa_stream_get_sample_spec(this->stream)->channels, this->swvolume); + result = value; + break; + + case AO_PROP_MUTE_VOL: + + this->muted = value; + + o = pa_context_set_sink_input_mute(this->pa_class->context, pa_stream_get_index(this->stream), + value, __xine_pa_context_success_callback, this->pa_class); + + result = value; + } - pa_context_set_sink_input_volume(this->pa_class->context, pa_stream_get_index(this->stream), - &this->cvolume, __xine_pa_context_success_callback, this); - - result = value; - break; + if (o) { + wait_for_operation(this, o); + pa_operation_unref(o); } - + + pa_threaded_mainloop_unlock(this->pa_class->mainloop); + return result; } static int ao_pulse_ctrl(ao_driver_t *this_gen, int cmd, ...) { pulse_driver_t *this = (pulse_driver_t *) this_gen; + pa_operation *o = NULL; + + pa_threaded_mainloop_lock(this->pa_class->mainloop); - if ( ! this->stream ) return 0; + if (!this->stream || + !this->pa_class->context || + pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + pa_stream_get_state(this->stream) != PA_STREAM_READY) { + pa_threaded_mainloop_unlock(this->pa_class->mainloop); + return 0; + } switch (cmd) { - case AO_CTRL_FLUSH_BUFFERS: - _x_assert(this->stream && this->pa_class->context); + case AO_CTRL_FLUSH_BUFFERS: - if(pa_stream_get_state(this->stream) == PA_STREAM_READY) { - pthread_mutex_t completion_callback = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&completion_callback); - pa_stream_flush(this->stream, __xine_pa_stream_success_callback, &completion_callback); + o = pa_stream_flush(this->stream, __xine_pa_stream_success_callback, this); + break; - pthread_mutex_lock(&completion_callback); - pthread_mutex_destroy(&completion_callback); - } + case AO_CTRL_PLAY_RESUME: + case AO_CTRL_PLAY_PAUSE: - this->frames_written = 0; + o = pa_stream_cork(this->stream, cmd == AO_CTRL_PLAY_PAUSE, __xine_pa_stream_success_callback, this); + break; + } - break; + if (o) { + wait_for_operation(this, o); + pa_operation_unref(o); } + pa_threaded_mainloop_unlock(this->pa_class->mainloop); + return 0; } @@ -515,21 +704,53 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da this = (pulse_driver_t *) xine_xmalloc (sizeof (pulse_driver_t)); if (!this) return NULL; + this->xine = class->xine; + this->host = NULL; + this->sink = NULL; + + device = this->xine->config->register_string(this->xine->config, + "audio.pulseaudio_device", + "", + _("device used for pulseaudio"), + _("use 'server[:sink]' for setting the " + "pulseaudio sink device."), + 10, NULL, + NULL); + + if (device && *device) { + char *sep = strrchr(device, ':'); + if ( sep ) { + if (!(this->host = strndup(device, sep-device))) { + free(this); + return NULL; + } + + if (!(this->sink = strdup(sep+1))) { + free(this->host); + free(this); + return NULL; + } + } else { + + if (!(this->host = strdup(device))) { + free(this); + return NULL; + } + } + } /* * set capabilities */ - this->capabilities = AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | AO_CAP_MODE_4CHANNEL | - AO_CAP_MODE_4_1CHANNEL | AO_CAP_MODE_5CHANNEL | - AO_CAP_MODE_5_1CHANNEL | AO_CAP_MIXER_VOL | - AO_CAP_PCM_VOL | AO_CAP_MUTE_VOL | AO_CAP_8BITS | - AO_CAP_16BITS | AO_CAP_FLOAT32; + this->capabilities = + AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | AO_CAP_MODE_4CHANNEL | + AO_CAP_MODE_4_1CHANNEL | AO_CAP_MODE_5CHANNEL | AO_CAP_MODE_5_1CHANNEL | + AO_CAP_MIXER_VOL | AO_CAP_PCM_VOL | AO_CAP_MUTE_VOL | + AO_CAP_8BITS | AO_CAP_16BITS | AO_CAP_FLOAT32; this->sample_rate = 0; - this->host = NULL; - this->sink = NULL; - + this->ao_driver.get_capabilities = ao_pulse_get_capabilities; this->ao_driver.get_property = ao_pulse_get_property; this->ao_driver.set_property = ao_pulse_set_property; @@ -541,27 +762,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da this->ao_driver.close = ao_pulse_close; this->ao_driver.exit = ao_pulse_exit; this->ao_driver.get_gap_tolerance = ao_pulse_get_gap_tolerance; - this->ao_driver.control = ao_pulse_ctrl; - - device = this->xine->config->register_string(this->xine->config, - "audio.pulseaudio_device", - "", - _("device used for pulseaudio"), - _("use 'server[:sink]' for setting the " - "pulseaudio sink device."), - 10, NULL, - NULL); - - if (device && *device) { - char *sep = strchr(device, ':'); - if ( sep ) { - this->host = strndup(device, sep-device); - this->sink = strdup(&sep[1]); - } else - this->host = strdup(device); - } - - pthread_mutex_init(&this->info_mutex, NULL); + this->ao_driver.control = ao_pulse_ctrl; xprintf (class->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: host %s sink %s\n", this->host ? this->host : "(null)", this->sink ? this->sink : "(null)"); @@ -587,10 +788,13 @@ static void dispose_class (audio_driver_class_t *this_gen) { pulse_class_t *this = (pulse_class_t *) this_gen; - if ( this->context ) + pa_threaded_mainloop_stop(this->mainloop); + + if (this->context) { + pa_context_disconnect(this->context); pa_context_unref(this->context); + } - pa_threaded_mainloop_stop(this->mainloop); pa_threaded_mainloop_free(this->mainloop); free (this); @@ -611,20 +815,18 @@ static void *init_class (xine_t *xine, void *data) { this->driver_class.get_description = get_description; this->driver_class.dispose = dispose_class; - this->xine = xine; + this->xine = xine; + this->context = NULL; this->mainloop = pa_threaded_mainloop_new(); _x_assert(this->mainloop); - pa_threaded_mainloop_start(this->mainloop); - - this->context = NULL; return this; } static const ao_info_t ao_info_pulse = { - 6 + 12 }; /* @@ -636,5 +838,3 @@ const plugin_info_t xine_plugin_info[] EXPORTED = { { PLUGIN_AUDIO_OUT, 8, "pulseaudio", XINE_VERSION_CODE, &ao_info_pulse, init_class }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; - - -- cgit v1.2.3 From a50219269aa4522530de7b7a26bc4e95a5cda1dd Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 2 Apr 2008 17:17:03 +0100 Subject: Add wvp to the wavpack demuxer's extensions list. --- src/combined/demux_wavpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/demux_wavpack.c b/src/combined/demux_wavpack.c index a9b20e5f9..754052199 100644 --- a/src/combined/demux_wavpack.c +++ b/src/combined/demux_wavpack.c @@ -387,7 +387,7 @@ static const char *get_identifier (demux_class_t *const this_gen) { } static const char *get_extensions (demux_class_t *const this_gen) { - return "wv"; + return "wv wvp"; } static const char *get_mimetypes (demux_class_t *const this_gen) { -- cgit v1.2.3 From 0950e968cef5be4d9d38ad59b27bbfcc238e7d3e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 4 Apr 2008 01:35:40 +0100 Subject: Updated PulseAudio driver (fixup) The problem was basically that detection if PA was available happened in open() instead of open_plugin(). --- src/audio_out/audio_pulse_out.c | 272 ++++++++++++++++++++++------------------ 1 file changed, 147 insertions(+), 125 deletions(-) (limited to 'src') diff --git a/src/audio_out/audio_pulse_out.c b/src/audio_out/audio_pulse_out.c index f5ade655f..cefcc7367 100644 --- a/src/audio_out/audio_pulse_out.c +++ b/src/audio_out/audio_pulse_out.c @@ -51,9 +51,6 @@ typedef struct { audio_driver_class_t driver_class; xine_t *xine; - - struct pa_context *context; /*< Pulseaudio connection context */ - struct pa_threaded_mainloop *mainloop; /*< Main event loop object */ } pulse_class_t; typedef struct pulse_driver_s { @@ -64,7 +61,10 @@ typedef struct pulse_driver_s { char *host; /*< The host to connect to */ char *sink; /*< The sink to connect to */ - struct pa_stream *stream; /*< Pulseaudio playback stream object */ + + pa_threaded_mainloop *mainloop; /*< Main event loop object */ + pa_context *context; /*< Pulseaudio connection context */ + pa_stream *stream; /*< Pulseaudio playback stream object */ pa_volume_t swvolume; int muted; @@ -88,7 +88,7 @@ typedef struct pulse_driver_s { */ static void __xine_pa_context_state_callback(pa_context *c, void *this_gen) { - pulse_class_t * this = (pulse_class_t*) this_gen; + pulse_driver_t * this = (pulse_driver_t*) this_gen; switch (pa_context_get_state(c)) { @@ -121,7 +121,7 @@ static void __xine_pa_stream_state_callback(pa_stream *s, void *this_gen) case PA_STREAM_READY: case PA_STREAM_TERMINATED: case PA_STREAM_FAILED: - pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); + pa_threaded_mainloop_signal(this->mainloop, 0); break; case PA_STREAM_UNCONNECTED: @@ -141,7 +141,7 @@ static void __xine_pa_stream_request_callback(pa_stream *s, size_t nbytes, void { pulse_driver_t * this = (pulse_driver_t*) this_gen; - pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); + pa_threaded_mainloop_signal(this->mainloop, 0); } /** @@ -154,7 +154,7 @@ static void __xine_pa_stream_notify_callback(pa_stream *s, void *this_gen) { pulse_driver_t * this = (pulse_driver_t*) this_gen; - pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); + pa_threaded_mainloop_signal(this->mainloop, 0); } /** @@ -169,9 +169,9 @@ static void __xine_pa_stream_success_callback(pa_stream *s, int success, void *t pulse_driver_t * this = (pulse_driver_t*) this_gen; if (!success) - xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: stream operation failed: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: stream operation failed: %s\n", pa_strerror(pa_context_errno(this->context))); - pa_threaded_mainloop_signal(this->pa_class->mainloop, 0); + pa_threaded_mainloop_signal(this->mainloop, 0); } /** @@ -183,7 +183,7 @@ static void __xine_pa_stream_success_callback(pa_stream *s, int success, void *t */ static void __xine_pa_context_success_callback(pa_context *c, int success, void *this_gen) { - pulse_class_t *this = (pulse_class_t*) this_gen; + pulse_driver_t *this = (pulse_driver_t*) this_gen; if (!success) xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: context operation failed: %s\n", pa_strerror(pa_context_errno(this->context))); @@ -209,7 +209,7 @@ static void __xine_pa_sink_info_callback(pa_context *c, const pa_sink_input_info if (is_last < 0) { xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: Failed to get sink input info: %s\n", - pa_strerror(pa_context_errno(this->pa_class->context))); + pa_strerror(pa_context_errno(this->context))); return; } @@ -221,6 +221,53 @@ static void __xine_pa_sink_info_callback(pa_context *c, const pa_sink_input_info this->muted = info->mute; } +static int connect_context(pulse_driver_t *this) { + + if (this->context && (pa_context_get_state(this->context) == PA_CONTEXT_FAILED || + pa_context_get_state(this->context) == PA_CONTEXT_TERMINATED)) { + pa_context_unref(this->context); + this->context = NULL; + } + + if (!this->context) { + char fn[PATH_MAX], *p; + + if (pa_get_binary_name(fn, sizeof(fn))) + p = pa_path_get_filename(fn); + else + p = "Xine"; + + this->context = pa_context_new(pa_threaded_mainloop_get_api(this->mainloop), p); + _x_assert(this->context); + + pa_context_set_state_callback(this->context, __xine_pa_context_state_callback, this); + } + + if (pa_context_get_state(this->context) == PA_CONTEXT_UNCONNECTED) { + + if (pa_context_connect(this->context, this->host, 0, NULL) < 0) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object %s\n", pa_strerror(pa_context_errno(this->context))); + return -1; + } + } + + for (;;) { + pa_context_state_t state = pa_context_get_state(this->context); + + if (state == PA_CONTEXT_FAILED || state == PA_CONTEXT_TERMINATED) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object: %s\n", pa_strerror(pa_context_errno(this->context))); + return -1; + } + + if (state == PA_CONTEXT_READY) + break; + + pa_threaded_mainloop_wait(this->mainloop); + } + + return 0; +} + /* * open the audio device for writing to */ @@ -240,14 +287,14 @@ static int ao_pulse_open(ao_driver_t *this_gen, return 0; } - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); if (this->stream) { if (mode == this->mode && rate == this->sample_rate && bits == this->bits_per_sample) { - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return this->sample_rate; } @@ -325,50 +372,11 @@ static int ao_pulse_open(ao_driver_t *this_gen, goto fail; } - if ( this->pa_class->context && (pa_context_get_state(this->pa_class->context) == PA_CONTEXT_FAILED || - pa_context_get_state(this->pa_class->context) == PA_CONTEXT_TERMINATED)) { - pa_context_unref(this->pa_class->context); - this->pa_class->context = NULL; - } - - if (!this->pa_class->context) { - char fn[PATH_MAX], *p; - - if (pa_get_binary_name(fn, sizeof(fn))) - p = pa_path_get_filename(fn); - else - p = "Xine"; - - this->pa_class->context = pa_context_new(pa_threaded_mainloop_get_api(this->pa_class->mainloop), p); - _x_assert(this->pa_class->context); - - pa_context_set_state_callback(this->pa_class->context, __xine_pa_context_state_callback, this->pa_class); - } - - if (pa_context_get_state(this->pa_class->context) == PA_CONTEXT_UNCONNECTED) { - - if (pa_context_connect(this->pa_class->context, this->host, 0, NULL) < 0) { - xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object\n"); - goto fail; - } - } - - for (;;) { - pa_context_state_t state = pa_context_get_state(this->pa_class->context); - - if (state == PA_CONTEXT_FAILED || state == PA_CONTEXT_TERMINATED) { - xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); - goto fail; - } - - if (state == PA_CONTEXT_READY) - break; - - pa_threaded_mainloop_wait(this->pa_class->mainloop); - } + if (connect_context(this) < 0) + goto fail; _x_assert(!this->stream); - this->stream = pa_stream_new(this->pa_class->context, "Audio Stream", &ss, &cm); + this->stream = pa_stream_new(this->context, "Audio Stream", &ss, &cm); _x_assert(this->stream); pa_stream_set_state_callback(this->stream, __xine_pa_stream_state_callback, this); @@ -380,28 +388,28 @@ static int ao_pulse_open(ao_driver_t *this_gen, NULL, NULL); for (;;) { - pa_context_state_t cstate = pa_context_get_state(this->pa_class->context); + pa_context_state_t cstate = pa_context_get_state(this->context); pa_stream_state_t sstate = pa_stream_get_state(this->stream); if (cstate == PA_CONTEXT_FAILED || cstate == PA_CONTEXT_TERMINATED || sstate == PA_STREAM_FAILED || sstate == PA_STREAM_TERMINATED) { - xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to connect context object: %s\n", pa_strerror(pa_context_errno(this->context))); goto fail; } if (sstate == PA_STREAM_READY) break; - pa_threaded_mainloop_wait(this->pa_class->mainloop); + pa_threaded_mainloop_wait(this->mainloop); } - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return this->sample_rate; fail: - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); this_gen->close(this_gen); return 0; } @@ -432,7 +440,7 @@ static int ao_pulse_write(ao_driver_t *this_gen, int16_t *data, int ret = -1; size_t done = 0; - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); while (size > 0) { size_t l; @@ -440,8 +448,8 @@ static int ao_pulse_write(ao_driver_t *this_gen, int16_t *data, for (;;) { if (!this->stream || - !this->pa_class->context || - pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + !this->context || + pa_context_get_state(this->context) != PA_CONTEXT_READY || pa_stream_get_state(this->stream) != PA_STREAM_READY) goto finish; @@ -451,7 +459,7 @@ static int ao_pulse_write(ao_driver_t *this_gen, int16_t *data, if (l > 0) break; - pa_threaded_mainloop_wait(this->pa_class->mainloop); + pa_threaded_mainloop_wait(this->mainloop); } if (l > size) @@ -467,7 +475,7 @@ static int ao_pulse_write(ao_driver_t *this_gen, int16_t *data, finish: - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); /* fprintf(stderr, "write-out\n"); */ @@ -482,14 +490,14 @@ static int ao_pulse_delay (ao_driver_t *this_gen) /* fprintf(stderr, "delay-in\n"); */ - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); for (;;) { pa_usec_t latency = 0; if (!this->stream || - !this->pa_class->context || - pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + !this->context || + pa_context_get_state(this->context) != PA_CONTEXT_READY || pa_stream_get_state(this->stream) != PA_STREAM_READY) goto finish; @@ -498,17 +506,17 @@ static int ao_pulse_delay (ao_driver_t *this_gen) goto finish; } - if (pa_context_errno(this->pa_class->context) != PA_ERR_NODATA) { - xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to query latency: %s\n", pa_strerror(pa_context_errno(this->pa_class->context))); + if (pa_context_errno(this->context) != PA_ERR_NODATA) { + xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_pulse_out: failed to query latency: %s\n", pa_strerror(pa_context_errno(this->context))); goto finish; } - pa_threaded_mainloop_wait(this->pa_class->mainloop); + pa_threaded_mainloop_wait(this->mainloop); } finish: - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return ret; } @@ -517,7 +525,7 @@ static void ao_pulse_close(ao_driver_t *this_gen) { pulse_driver_t *this = (pulse_driver_t *) this_gen; - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); if (this->stream) { pa_stream_disconnect(this->stream); @@ -525,7 +533,7 @@ static void ao_pulse_close(ao_driver_t *this_gen) this->stream = NULL; } - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); } static uint32_t ao_pulse_get_capabilities (ao_driver_t *this_gen) { @@ -539,7 +547,20 @@ static void ao_pulse_exit(ao_driver_t *this_gen) { ao_pulse_close(this_gen); - free (this); + pa_threaded_mainloop_lock(this->mainloop); + + if (this->context) { + pa_context_disconnect(this->context); + pa_context_unref(this->context); + } + + pa_threaded_mainloop_unlock(this->mainloop); + + pa_threaded_mainloop_free(this->mainloop); + + free(this->host); + free(this->sink); + free(this); } static int wait_for_operation(pulse_driver_t *this, pa_operation *o) { @@ -547,15 +568,15 @@ static int wait_for_operation(pulse_driver_t *this, pa_operation *o) { for (;;) { if (!this->stream || - !this->pa_class->context || - pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + !this->context || + pa_context_get_state(this->context) != PA_CONTEXT_READY || pa_stream_get_state(this->stream) != PA_STREAM_READY) return -1; if (pa_operation_get_state(o) != PA_OPERATION_RUNNING) return 0; - pa_threaded_mainloop_wait(this->pa_class->mainloop); + pa_threaded_mainloop_wait(this->mainloop); } } @@ -564,13 +585,13 @@ static int ao_pulse_get_property (ao_driver_t *this_gen, int property) { int result = 0; pa_operation *o = NULL; - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); if (!this->stream || - !this->pa_class->context || - pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + !this->context || + pa_context_get_state(this->context) != PA_CONTEXT_READY || pa_stream_get_state(this->stream) != PA_STREAM_READY) { - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return 0; } @@ -580,7 +601,7 @@ static int ao_pulse_get_property (ao_driver_t *this_gen, int property) { case AO_PROP_PCM_VOL: case AO_PROP_MIXER_VOL: - o = pa_context_get_sink_input_info(this->pa_class->context, pa_stream_get_index(this->stream), + o = pa_context_get_sink_input_info(this->context, pa_stream_get_index(this->stream), __xine_pa_sink_info_callback, this); break; @@ -603,7 +624,7 @@ static int ao_pulse_get_property (ao_driver_t *this_gen, int property) { break; } - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return result; } @@ -613,13 +634,13 @@ static int ao_pulse_set_property (ao_driver_t *this_gen, int property, int value int result = ~value; pa_operation *o = NULL; - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); if (!this->stream || - !this->pa_class->context || - pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + !this->context || + pa_context_get_state(this->context) != PA_CONTEXT_READY || pa_stream_get_state(this->stream) != PA_STREAM_READY) { - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return 0; } @@ -630,8 +651,8 @@ static int ao_pulse_set_property (ao_driver_t *this_gen, int property, int value this->swvolume = pa_sw_volume_from_linear((double)value/100.0); pa_cvolume_set(&this->cvolume, pa_stream_get_sample_spec(this->stream)->channels, this->swvolume); - o = pa_context_set_sink_input_volume(this->pa_class->context, pa_stream_get_index(this->stream), - &this->cvolume, __xine_pa_context_success_callback, this->pa_class); + o = pa_context_set_sink_input_volume(this->context, pa_stream_get_index(this->stream), + &this->cvolume, __xine_pa_context_success_callback, this); result = value; break; @@ -640,8 +661,8 @@ static int ao_pulse_set_property (ao_driver_t *this_gen, int property, int value this->muted = value; - o = pa_context_set_sink_input_mute(this->pa_class->context, pa_stream_get_index(this->stream), - value, __xine_pa_context_success_callback, this->pa_class); + o = pa_context_set_sink_input_mute(this->context, pa_stream_get_index(this->stream), + value, __xine_pa_context_success_callback, this); result = value; } @@ -651,7 +672,7 @@ static int ao_pulse_set_property (ao_driver_t *this_gen, int property, int value pa_operation_unref(o); } - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return result; } @@ -660,13 +681,13 @@ static int ao_pulse_ctrl(ao_driver_t *this_gen, int cmd, ...) { pulse_driver_t *this = (pulse_driver_t *) this_gen; pa_operation *o = NULL; - pa_threaded_mainloop_lock(this->pa_class->mainloop); + pa_threaded_mainloop_lock(this->mainloop); if (!this->stream || - !this->pa_class->context || - pa_context_get_state(this->pa_class->context) != PA_CONTEXT_READY || + !this->context || + pa_context_get_state(this->context) != PA_CONTEXT_READY || pa_stream_get_state(this->stream) != PA_STREAM_READY) { - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return 0; } @@ -689,7 +710,7 @@ static int ao_pulse_ctrl(ao_driver_t *this_gen, int cmd, ...) { pa_operation_unref(o); } - pa_threaded_mainloop_unlock(this->pa_class->mainloop); + pa_threaded_mainloop_unlock(this->mainloop); return 0; } @@ -697,7 +718,8 @@ static int ao_pulse_ctrl(ao_driver_t *this_gen, int cmd, ...) { static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *data) { pulse_class_t *class = (pulse_class_t *) class_gen; pulse_driver_t *this; - char *device; + const char* device; + int r; lprintf ("audio_pulse_out: open_plugin called\n"); @@ -708,15 +730,17 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da this->xine = class->xine; this->host = NULL; this->sink = NULL; + this->context = NULL; + this->mainloop = NULL; - device = this->xine->config->register_string(this->xine->config, - "audio.pulseaudio_device", - "", - _("device used for pulseaudio"), - _("use 'server[:sink]' for setting the " - "pulseaudio sink device."), - 10, NULL, - NULL); + device = class->xine->config->register_string(class->xine->config, + "audio.pulseaudio_device", + "", + _("device used for pulseaudio"), + _("use 'server[:sink]' for setting the " + "pulseaudio sink device."), + 10, NULL, + NULL); if (device && *device) { char *sep = strrchr(device, ':'); @@ -740,6 +764,10 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da } } + this->mainloop = pa_threaded_mainloop_new(); + _x_assert(this->mainloop); + pa_threaded_mainloop_start(this->mainloop); + /* * set capabilities */ @@ -769,6 +797,15 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da this->pa_class = class; + pa_threaded_mainloop_lock(this->mainloop); + r = connect_context(this); + pa_threaded_mainloop_unlock(this->mainloop); + + if (r < 0) { + ao_pulse_exit((ao_driver_t *) this); + return NULL; + } + return &this->ao_driver; } @@ -788,16 +825,7 @@ static void dispose_class (audio_driver_class_t *this_gen) { pulse_class_t *this = (pulse_class_t *) this_gen; - pa_threaded_mainloop_stop(this->mainloop); - - if (this->context) { - pa_context_disconnect(this->context); - pa_context_unref(this->context); - } - - pa_threaded_mainloop_free(this->mainloop); - - free (this); + free(this); } static void *init_class (xine_t *xine, void *data) { @@ -810,18 +838,12 @@ static void *init_class (xine_t *xine, void *data) { if (!this) return NULL; + this->xine = xine; this->driver_class.open_plugin = open_plugin; this->driver_class.get_identifier = get_identifier; this->driver_class.get_description = get_description; this->driver_class.dispose = dispose_class; - this->xine = xine; - this->context = NULL; - - this->mainloop = pa_threaded_mainloop_new(); - _x_assert(this->mainloop); - pa_threaded_mainloop_start(this->mainloop); - return this; } -- cgit v1.2.3 From 1263a3ae411fe768568092ed755d08794d8f6b93 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sat, 5 Apr 2008 00:53:25 +0100 Subject: Fix a regression in the Matroska demuxer. One '&'... --- src/demuxers/ebml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 0c633643f..4ce8a549d 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -327,7 +327,7 @@ char *ebml_alloc_read_ascii (ebml_parser_t *ebml, ebml_elem_t *elem) if (text) { text[elem->len] = '\0'; - if (ebml_read_ascii (ebml, &elem, text)) + if (ebml_read_ascii (ebml, elem, text)) return text; free (text); } -- cgit v1.2.3 From 1397c2baedd7a1f4a203c4a1ce14d8a46ba5d523 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Apr 2008 19:28:32 +0100 Subject: Add some newer Ogg MIME types. --- src/demuxers/demux_ogg.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 175d61cd8..33c262793 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -2166,6 +2166,9 @@ static const char *ogg_get_extensions (demux_class_t *this_gen) { static const char *ogg_get_mimetypes (demux_class_t *this_gen) { return "application/ogg: ogx: Ogg Stream;" "application/x-ogg: ogx: Ogg Stream;" + "application/x-ogm: ogx: Ogg Stream;" + "application/x-ogm-audio: oga: Ogg Audio;" + "application/x-ogm-video: ogv: Ogg Video;" "audio/ogg: oga: Ogg Audio;" "audio/x-ogg: oga: Ogg Audio;" "video/ogg: ogv: Ogg Video;" -- cgit v1.2.3 From aae81ebc2ba5f815d8cc153b1edabb70fda440ca Mon Sep 17 00:00:00 2001 From: Jinghua Luo Date: Mon, 7 Apr 2008 17:27:49 +0100 Subject: ffmpeg/libreal cleanup --- src/combined/ffmpeg/ff_audio_decoder.c | 2 +- src/libreal/xine_real_audio_decoder.c | 46 ++++++++++++++++++---------------- src/libreal/xine_real_video_decoder.c | 43 ++++++++++++++++++------------- 3 files changed, 50 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 4aebd6d60..ef97f93bf 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -324,7 +324,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) /* fill up this buffer */ xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], - bytes_to_send); + bytes_to_send); /* byte count / 2 (bytes / sample) / channels */ audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; diff --git a/src/libreal/xine_real_audio_decoder.c b/src/libreal/xine_real_audio_decoder.c index 1b21de2d0..a90144b95 100644 --- a/src/libreal/xine_real_audio_decoder.c +++ b/src/libreal/xine_real_audio_decoder.c @@ -51,6 +51,8 @@ typedef struct { /* empty so far */ } real_class_t; +typedef void * ra_codec_t; + typedef struct realdec_decoder_s { audio_decoder_t audio_decoder; @@ -60,18 +62,18 @@ typedef struct realdec_decoder_s { void *ra_handle; - unsigned long (*raCloseCodec)(void*); - unsigned long (*raDecode)(void*, char*,unsigned long,char*,unsigned int*,long); - unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long); - unsigned long (*raFreeDecoder)(void*); - void* (*raGetFlavorProperty)(void*,unsigned long,unsigned long,int*); - unsigned long (*raInitDecoder)(void*, void*); - unsigned long (*raOpenCodec2)(void*); - unsigned long (*raSetFlavor)(void*,unsigned long); - void (*raSetDLLAccessPath)(char*); - void (*raSetPwd)(char*,char*); + uint32_t (*raCloseCodec)(ra_codec_t); + uint32_t (*raDecode)(ra_codec_t, char *, uint32_t, char *, uint32_t *, uint32_t); + uint32_t (*raFlush)(ra_codec_t, char *, uint32_t *); + uint32_t (*raFreeDecoder)(ra_codec_t); + void * (*raGetFlavorProperty)(ra_codec_t, uint16_t, uint16_t, uint16_t *); + uint32_t (*raInitDecoder)(ra_codec_t, void *); + uint32_t (*raOpenCodec2)(ra_codec_t *, const char *); + uint32_t (*raSetFlavor)(ra_codec_t, uint16_t); + void (*raSetDLLAccessPath)(char *); + void (*raSetPwd)(ra_codec_t, char *); - void *context; + ra_codec_t context; int sps, w, h; int block_align; @@ -92,14 +94,14 @@ typedef struct realdec_decoder_s { } realdec_decoder_t; typedef struct { - int samplerate; - short bits; - short channels; - int unk1; - int subpacket_size; - int coded_frame_size; - int codec_data_length; - void *extras; + uint32_t samplerate; + uint16_t bits; + uint16_t channels; + uint16_t quality; + uint32_t subpacket_size; + uint32_t coded_frame_size; + uint32_t codec_data_length; + void *extras; } ra_init_t; static int load_syms_linux (realdec_decoder_t *this, const char *const codec_name, const char *const codec_alternate) { @@ -254,7 +256,7 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { * init codec */ - result = this->raOpenCodec2 (&this->context); + result = this->raOpenCodec2 (&this->context, NULL); if (result) { xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libareal: error in raOpenCodec2: %d\n", result); return 0; @@ -266,7 +268,7 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { init_data.samplerate = samples_per_sec; init_data.bits = bits_per_sample; init_data.channels = num_channels; - init_data.unk1 = 100; /* ??? */ + init_data.quality = 100; /* ??? */ init_data.subpacket_size = subpacket_size; /* subpacket size */ init_data.coded_frame_size = coded_frame_size; /* coded frame size */ init_data.codec_data_length = data_len; /* codec data length */ @@ -506,7 +508,7 @@ static void realdec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - n+=this->block_align; + n += this->block_align; } } } diff --git a/src/libreal/xine_real_video_decoder.c b/src/libreal/xine_real_video_decoder.c index d68c7390e..57046a5f2 100644 --- a/src/libreal/xine_real_video_decoder.c +++ b/src/libreal/xine_real_video_decoder.c @@ -63,9 +63,9 @@ typedef struct realdec_decoder_s { uint32_t (*rvyuv_custom_message)(void*, void*); uint32_t (*rvyuv_free)(void*); - uint32_t (*rvyuv_hive_message)(uint32_t, uint32_t); + uint32_t (*rvyuv_hive_message)(uint32_t, void*); uint32_t (*rvyuv_init)(void*, void*); /* initdata,context */ - uint32_t (*rvyuv_transform)(char*, char*, void*, uint32_t*,void*); + uint32_t (*rvyuv_transform)(char*, char*, void*, void*, void*); void *context; @@ -113,13 +113,21 @@ typedef struct cmsg_data_s { typedef struct transform_in_s { uint32_t len; - uint32_t unknown1; - uint32_t chunks; - uint32_t* extra; - uint32_t unknown2; + uint32_t interpolate; + uint32_t nsegments; + void *segments; + uint32_t flags; uint32_t timestamp; } transform_in_t; +typedef struct { + uint32_t frames; + uint32_t notes; + uint32_t timestamp; + uint32_t width; + uint32_t height; +} transform_out_t; + /* * real codec loader */ @@ -169,7 +177,6 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { int result; rv_init_t init_data = {11, 0, 0, 0, 0, 0, 1, 0}; /* rv30 */ - switch (buf->type) { case BUF_VIDEO_RV20: _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Real Video 2.0"); @@ -258,7 +265,7 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { #ifdef LOG printf ("libreal: CustomMessage cmsg_data:\n"); - xine_hexdump ((uint8_t *) cmsg_data, sizeof (cmsg_data)); + xine_hexdump ((uint8_t *) &cmsg_data, sizeof (cmsg_data)); printf ("libreal: cmsg24:\n"); xine_hexdump ((uint8_t *) cmsg24, (buf->size - 34 + 2) * sizeof(uint32_t)); #endif @@ -342,7 +349,7 @@ static void realdec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) int result; vo_frame_t *img; - uint32_t transform_out[5]; + transform_out_t transform_out; transform_in_t transform_in = { this->chunk_buffer_size, /* length of the packet (sub-packets appended) */ @@ -369,7 +376,7 @@ static void realdec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) xine_hexdump (this->chunk_buffer, this->chunk_buffer_size); printf ("libreal: transform_in:\n"); - xine_hexdump ((uint8_t *) transform_in, 6 * 4); + xine_hexdump ((uint8_t *) &transform_in, sizeof(rv_xform_in_t)); printf ("libreal: chunk_table:\n"); xine_hexdump ((uint8_t *) buf->decoder_info_ptr[2], @@ -379,21 +386,21 @@ static void realdec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) result = this->rvyuv_transform (this->chunk_buffer, this->frame_buffer, &transform_in, - transform_out, + &transform_out, this->context); lprintf ("transform result: %08x\n", result); lprintf ("transform_out:\n"); - #ifdef LOG - xine_hexdump ((uint8_t *) transform_out, 5 * 4); - #endif +#ifdef LOG + xine_hexdump ((uint8_t *) &transform_out, 5 * 4); +#endif /* Sometimes the stream contains video of a different size * to that specified in the realmedia header */ - if(transform_out[0] && ((transform_out[3] != this->width) || - (transform_out[4] != this->height))) { - this->width = transform_out[3]; - this->height = transform_out[4]; + if(transform_out.frames && ((transform_out.width != this->width) || + (transform_out.height != this->height))) { + this->width = transform_out.width; + this->height = transform_out.height; this->frame_size = this->width * this->height; -- cgit v1.2.3 From d3bb60048b4ff30adc379f5e1eab62db8354db8b Mon Sep 17 00:00:00 2001 From: Jinghua Luo Date: Mon, 7 Apr 2008 17:27:49 +0100 Subject: Use ffmpeg's cook decoder and fix Real decoder bugs This patch drops support for RV20. --- src/combined/ffmpeg/ff_audio_decoder.c | 73 ++++++++++++-- src/combined/ffmpeg/ff_video_decoder.c | 20 ++++ src/demuxers/demux_real.c | 170 ++++++++++++++++++++++++++++++++- src/demuxers/demux_realaudio.c | 114 ++++++++++++++++++++-- src/libreal/xine_real_audio_decoder.c | 118 +++-------------------- src/libreal/xine_real_video_decoder.c | 3 +- 6 files changed, 372 insertions(+), 126 deletions(-) (limited to 'src') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index ef97f93bf..82b921c8d 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -199,8 +199,8 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->audio_channels = this->buf[0x37]; /* this->audio_bits = buf->content[0x35] */ - this->context->block_align = _X_BE_16(&this->buf[0x2A]); - + this->context->block_align = _X_BE_32(&this->buf[0x18]); + this->context->extradata_size = 5*sizeof(short); this->context->extradata = xine_xmalloc(this->context->extradata_size); @@ -211,7 +211,46 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) ptr[2] = _X_BE_16(&this->buf[0x16]); /* subpacket flavour */ ptr[3] = _X_BE_32(&this->buf[0x18]); /* coded frame size */ ptr[4] = 0; /* codec's data length */ + + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "ffmpeg_audio_dec: 28_8 audio channels %d bits %d sample rate %d block align %d\n", + this->audio_channels, this->audio_bits, this->audio_sample_rate, + this->context->block_align); break; + case BUF_AUDIO_COOK: + { + int version; + int data_len; + uint8_t * extradata; + + version = _X_BE_16 (this->buf+4); + if (version == 4) { + this->audio_sample_rate = _X_BE_16 (this->buf+48); + this->audio_bits = _X_BE_16 (this->buf+52); + this->audio_channels = _X_BE_16 (this->buf+54); + data_len = _X_BE_32 (this->buf+67); + extradata = this->buf + 71; + } else { + this->audio_sample_rate = _X_BE_16 (this->buf+54); + this->audio_bits = _X_BE_16 (this->buf+58); + this->audio_channels = _X_BE_16 (this->buf+60); + data_len = _X_BE_32 (this->buf+74); + extradata = this->buf + 78; + } + this->context->block_align = _X_BE_16 (this->buf+44); + + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "ffmpeg_audio_dec: cook audio channels %d bits %d sample rate %d block align %d\n", + this->audio_channels, this->audio_bits, this->audio_sample_rate, + this->context->block_align); + + this->context->extradata_size = data_len; + this->context->extradata = xine_xmalloc(this->context->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + xine_fast_memcpy (this->context->extradata, extradata, + this->context->extradata_size); + break; + } default: xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type); @@ -228,6 +267,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->context->sample_rate = this->audio_sample_rate; this->context->channels = this->audio_channels; this->context->codec_id = this->codec->id; + this->context->codec_type = this->codec->type; this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); this->size = 0; @@ -267,7 +307,26 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->decoder_ok = 1; } + if( buf->decoder_flags & BUF_FLAG_PREVIEW ) + return; + + ff_audio_ensure_buffer_size(this, this->size + buf->size); + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; + if (!this->output_open) { + if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) { + avcodec_decode_audio (this->context, + (int16_t *)this->decode_buffer, + &decode_buffer_size, + &this->buf[0], + this->size); + this->audio_bits = this->context->bits_per_sample; + this->audio_sample_rate = this->context->sample_rate; + this->audio_channels = this->context->channels; + if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) + return; + } this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, this->stream, this->audio_bits, this->audio_sample_rate, _x_ao_channels2mode(this->audio_channels)); @@ -277,13 +336,6 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) if (!this->output_open) return; - if( buf->decoder_flags & BUF_FLAG_PREVIEW ) - return; - - ff_audio_ensure_buffer_size(this, this->size + buf->size); - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ offset = 0; @@ -355,7 +407,8 @@ static void ff_audio_reset (audio_decoder_t *this_gen) { if( this->context && this->decoder_ok ) { pthread_mutex_lock (&ffmpeg_lock); avcodec_close (this->context); - avcodec_open (this->context, this->codec); + if (avcodec_open (this->context, this->codec) < 0) + this->decoder_ok = 0; pthread_mutex_unlock (&ffmpeg_lock); } } diff --git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c index 4e772dbca..02282990b 100644 --- a/src/combined/ffmpeg/ff_video_decoder.c +++ b/src/combined/ffmpeg/ff_video_decoder.c @@ -944,6 +944,26 @@ static void ff_handle_header_buffer (ff_video_decoder_t *this, buf_element_t *bu this->context->slice_offset = xine_xmalloc(sizeof(int)*SLICE_OFFSET_SIZE); this->slice_offset_size = SLICE_OFFSET_SIZE; + this->context->extradata_size = this->size - 26; + if (this->context->extradata_size < 8) { + this->context->extradata_size= 8; + this->context->extradata = malloc(this->context->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + ((uint32_t *)this->context->extradata)[0] = 0; + if (codec_type == BUF_VIDEO_RV10) + ((uint32_t *)this->context->extradata)[1] = 0x10000000; + else + ((uint32_t *)this->context->extradata)[1] = 0x10003001; + } else { + this->context->extradata = malloc(this->context->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, this->buf + 26, + this->context->extradata_size); + } + + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "ffmpeg_video_dec: buf size %d\n", this->size); + lprintf("w=%d, h=%d\n", this->bih.biWidth, this->bih.biHeight); break; diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 60075d750..f0724a992 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -113,6 +113,12 @@ typedef struct { int index_entries; mdpr_t *mdpr; + int sps, cfs, w, h; + int block_align; + int frame_size; + uint8_t *frame_buffer; + uint32_t frame_num_bytes; + uint32_t sub_packet_cnt; } real_stream_t; typedef struct { @@ -168,6 +174,12 @@ typedef struct { demux_class_t demux_class; } demux_real_class_t; +static const unsigned char sipr_swaps[38][2] = { + {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, + {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, + {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, + {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, + {77,80}}; static void real_parse_index(demux_real_t *this) { @@ -316,6 +328,64 @@ static void real_free_mdpr (mdpr_t *mdpr) { free (mdpr); } +static void real_parse_audio_specific_data (demux_real_t *this, + real_stream_t * stream, + uint8_t * data, int len) +{ + int coded_frame_size; + int codec_data_length; + int coded_frame_size2; + int subpacket_size; + + coded_frame_size = _X_BE_32 (data+24); + codec_data_length = _X_BE_16 (data+40); + coded_frame_size2 = _X_BE_16 (data+42); + subpacket_size = _X_BE_16 (data+44); + + stream->sps = subpacket_size; + stream->w = coded_frame_size2; + stream->h = codec_data_length; + stream->block_align = coded_frame_size2; + stream->cfs = coded_frame_size; + + switch (stream->buf_type) { + case BUF_AUDIO_COOK: + case BUF_AUDIO_ATRK: + stream->block_align = subpacket_size; + break; + + case BUF_AUDIO_14_4: + break; + + case BUF_AUDIO_28_8: + stream->block_align = stream->cfs; + break; + + case BUF_AUDIO_SIPRO: + /* this->block_align = 19; */ + break; + + default: + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: error, i don't handle buf type 0x%08x\n", stream->buf_type); + } + + if (stream->sps) { + stream->frame_size = stream->w / stream->sps * stream->h * stream->sps; + stream->frame_buffer = xine_xmalloc (stream->frame_size); + stream->frame_num_bytes = 0; + } else { + stream->frame_size = stream->w * stream->h; + stream->frame_buffer = xine_xmalloc (stream->frame_size); + stream->frame_num_bytes = 0; + } + stream->sub_packet_cnt = 0; + + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + "demux_real: buf type 0x%08x frame size %dblock align %d\n", stream->buf_type, + stream->frame_size, stream->block_align); + +} static void real_parse_headers (demux_real_t *this) { @@ -426,8 +496,16 @@ static void real_parse_headers (demux_real_t *this) { mdpr = real_parse_mdpr (chunk_buffer); lprintf ("parsing type specific data...\n"); + if(!strcmp(mdpr->mime_type, "audio/X-MP3-draft-00")) { + lprintf ("mpeg layer 3 audio detected...\n"); - if(_X_BE_32(mdpr->type_specific_data) == RA_TAG) { + fourcc = ME_FOURCC('a', 'd', 'u', 0x55); + this->audio_streams[this->num_audio_streams].fourcc = fourcc; + this->audio_streams[this->num_audio_streams].buf_type = _x_formattag_to_buf_audio(fourcc); + this->audio_streams[this->num_audio_streams].index = NULL; + this->audio_streams[this->num_audio_streams].mdpr = mdpr; + this->num_audio_streams++; + } else if(_X_BE_32(mdpr->type_specific_data) == RA_TAG) { int version, len; if(this->num_audio_streams == MAX_AUDIO_STREAMS) { @@ -465,6 +543,10 @@ static void real_parse_headers (demux_real_t *this) { this->audio_streams[this->num_audio_streams].index = NULL; this->audio_streams[this->num_audio_streams].mdpr = mdpr; + real_parse_audio_specific_data (this, + &this->audio_streams[this->num_audio_streams], + mdpr->type_specific_data, + mdpr->type_specific_len); this->num_audio_streams++; } else if(_X_BE_32(mdpr->type_specific_data + 4) == VIDO_TAG) { @@ -985,6 +1067,7 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { off_t offset, input_length = 0; int normpos = 0; + read_next_packet: if(this->reference_mode) return demux_real_parse_references(this); @@ -1322,6 +1405,86 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { } free(sizes); + } else if (this->audio_stream->buf_type == BUF_AUDIO_COOK || + this->audio_stream->buf_type == BUF_AUDIO_ATRK || + this->audio_stream->buf_type == BUF_AUDIO_28_8 || + this->audio_stream->buf_type == BUF_AUDIO_SIPRO) { + /* reorder */ + uint8_t * buffer = this->audio_stream->frame_buffer; + int sps = this->audio_stream->sps; + int sph = this->audio_stream->h; + int cfs = this->audio_stream->cfs; + int w = this->audio_stream->w; + int spc = this->audio_stream->sub_packet_cnt; + int x, pos; + + switch (this->audio_stream->buf_type) { + case BUF_AUDIO_28_8: + for (x = 0; x < sph / 2; x++) { + pos = x * 2 * w + spc * cfs; + if(this->input->read(this->input, buffer + pos, cfs) < cfs) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: failed to read audio chunk\n"); + + this->status = DEMUX_FINISHED; + return this->status; + } + } + break; + case BUF_AUDIO_COOK: + case BUF_AUDIO_ATRK: + for (x = 0; x < w / sps; x++) { + pos = sps * (sph * x + ((sph + 1) / 2) * (spc & 1) + (spc >> 1)); + if(this->input->read(this->input, buffer + pos, sps) < sps) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: failed to read audio chunk\n"); + + this->status = DEMUX_FINISHED; + return this->status; + } + } + break; + case BUF_AUDIO_SIPRO: + pos = spc * w; + if(this->input->read(this->input, buffer + pos, w) < w) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: failed to read audio chunk\n"); + + this->status = DEMUX_FINISHED; + return this->status; + } + if (spc == sph - 1) { + int n; + int bs = sph * w * 2 / 96; /* nibbles per subpacket */ + /* Perform reordering */ + for(n=0; n < 38; n++) { + int j; + int i = bs * sipr_swaps[n][0]; + int o = bs * sipr_swaps[n][1]; + /* swap nibbles of block 'i' with 'o' TODO: optimize */ + for(j = 0;j < bs; j++) { + int x = (i & 1) ? (buffer[i >> 1] >> 4) : (buffer[i >> 1] & 0x0F); + int y = (o & 1) ? (buffer[o >> 1] >> 4) : (buffer[o >> 1] & 0x0F); + if(o & 1) + buffer[o >> 1] = (buffer[o >> 1] & 0x0F) | (x << 4); + else + buffer[o >> 1] = (buffer[o >> 1] & 0xF0) | x; + if(i & 1) + buffer[i >> 1] = (buffer[i >> 1] & 0x0F) | (y << 4); + else + buffer[i >> 1] = (buffer[i >> 1] & 0xF0) | y; + ++i; ++o; + } + } + } + break; + } + if(++this->audio_stream->sub_packet_cnt == sph) { + this->audio_stream->sub_packet_cnt = 0; + _x_demux_send_data(this->audio_fifo, buffer, this->audio_stream->frame_size, + pts, this->audio_stream->buf_type, 0, normpos, input_time, + this->duration, 0); + } } else { if(_x_demux_read_send_data(this->audio_fifo, this->input, size, pts, this->audio_stream->buf_type, 0, normpos, @@ -1471,6 +1634,9 @@ static int demux_real_seek (demux_plugin_t *this_gen, this->input->seek(this->input, index[i].offset, SEEK_SET); if(playing) { + if(this->audio_stream) + this->audio_stream->sub_packet_cnt = 0; + this->buf_flag_seek = 1; _x_demux_flush_engine(this->stream); } @@ -1509,6 +1675,8 @@ static void demux_real_dispose (demux_plugin_t *this_gen) { real_free_mdpr(this->audio_streams[i].mdpr); if(this->audio_streams[i].index) free(this->audio_streams[i].index); + if(this->audio_streams[i].frame_buffer) + free(this->audio_streams[i].frame_buffer); } if(this->fragment_tab) diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c index b663912b8..2075f1b6f 100644 --- a/src/demuxers/demux_realaudio.c +++ b/src/demuxers/demux_realaudio.c @@ -62,6 +62,10 @@ typedef struct { off_t data_start; off_t data_size; + int sps, cfs, w, h; + int frame_size; + uint8_t *frame_buffer; + unsigned char *header; unsigned int header_size; } demux_ra_t; @@ -70,6 +74,16 @@ typedef struct { demux_class_t demux_class; } demux_ra_class_t; +static const unsigned char sipr_swaps[38][2]={ + {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, + {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, + {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, + {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, + {77,80}}; + +/* Map flavour to bytes per second */ +static int sipr_fl2bps[4] = {813, 1062, 625, 2000}; // 6.5, 8.5, 5, 16 kbit per second + /* returns 1 if the RealAudio file was opened successfully, 0 otherwise */ static int open_ra_file(demux_ra_t *this) { unsigned char file_header[RA_FILE_HEADER_PREV_SIZE], len; @@ -165,20 +179,41 @@ static int open_ra_file(demux_ra_t *this) { offset++; /* Fourcc for version 3 comes after meta info */ - if((version == 3) && ((offset+7) <= this->header_size)) { - if(this->header[offset+2] == 4) - this->fourcc = _X_ME_32(&this->header[offset+3]); - else { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_realaudio: invalid fourcc size %d\n", this->header[offset+2]); - free(this->header); - return 0; + if(version == 3) { + if (((offset+7) <= this->header_size)) { + if(this->header[offset+2] == 4) + this->fourcc = _X_ME_32(&this->header[offset+3]); + else { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_realaudio: invalid fourcc size %d\n", this->header[offset+2]); + free(this->header); + return 0; + } + } else { + this->fourcc = ME_FOURCC('l', 'p', 'c', 'J'); } } _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC, this->fourcc); this->audio_type = _x_formattag_to_buf_audio(this->fourcc); + if (version == 4) { + this->sps = _X_BE_16 (this->header+44); + this->w = _X_BE_16 (this->header+42); + this->h = _X_BE_16 (this->header+40); + this->cfs = _X_BE_32 (this->header+24); + if (this->sps) { + this->frame_size = this->sps * this->h * this->sps; + this->frame_buffer = xine_xmalloc (this->frame_size); + } else { + this->frame_size = this->w * this->h; + this->frame_buffer = xine_xmalloc (this->frame_size); + } + + if (this->audio_type == BUF_AUDIO_28_8 || this->audio_type == BUF_AUDIO_SIPRO) + this->block_align = this->cfs; + } + /* seek to start of data */ this->data_start = this->header_size; if (this->input->seek(this->input, this->data_start, SEEK_SET) != @@ -212,7 +247,65 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { this->seek_flag = 0; } - if(_x_demux_read_send_data(this->audio_fifo, this->input, this->block_align, + if (this->audio_type == BUF_AUDIO_28_8 || this->audio_type == BUF_AUDIO_SIPRO) { + int x; + uint8_t * buffer; + + buffer = this->frame_buffer; + if (this->audio_type == BUF_AUDIO_SIPRO) { + int n; + int len = this->h * this->w; + int bs = len * 2 / 96; /* nibbles per subpacket */ + if(this->input->read(this->input, this->frame_buffer, len) < len) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_realaudio: failed to read audio chunk\n"); + + this->status = DEMUX_FINISHED; + return this->status; + } + /* Perform reordering */ + for(n = 0; n < 38; n++) { + int j; + int i = bs * sipr_swaps[n][0]; + int o = bs * sipr_swaps[n][1]; + /* swap nibbles of block 'i' with 'o' TODO: optimize */ + for(j = 0; j < bs; j++) { + int x = (i & 1) ? (this->frame_buffer[i >> 1] >> 4) : (this->frame_buffer[i >> 1] & 0x0F); + int y = (o & 1) ? (this->frame_buffer[o >> 1] >> 4) : (this->frame_buffer[o >> 1] & 0x0F); + if(o & 1) + this->frame_buffer[o >> 1] = (this->frame_buffer[o >> 1] & 0x0F) | (x << 4); + else + this->frame_buffer[o >> 1] = (this->frame_buffer[o >> 1] & 0xF0) | x; + if(i & 1) + this->frame_buffer[i >> 1] = (this->frame_buffer[i >> 1] & 0x0F) | (y << 4); + else + this->frame_buffer[i >> 1] = (this->frame_buffer[i >> 1] & 0xF0) | y; + ++i; ++o; + } + } + } else { + int x, y; + int pos; + + for (y = 0; y < this->h; y++) + for (x = 0; x < this->h / 2; x++) { + pos = x * 2 * this->w + y * this->cfs; + if(this->input->read(this->input, this->frame_buffer + pos, + this->cfs) < this->cfs) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_realaudio: failed to read audio chunk\n"); + + this->status = DEMUX_FINISHED; + return this->status; + } + } + } + + _x_demux_send_data(this->audio_fifo, + buffer, this->frame_size, + current_pts, this->audio_type, 0, + current_normpos, current_pts / 90, 0, 0); + } else if(_x_demux_read_send_data(this->audio_fifo, this->input, this->block_align, current_pts, this->audio_type, 0, current_normpos, current_pts / 90, 0, 0) < 0) { this->status = DEMUX_FINISHED; @@ -299,6 +392,8 @@ static void demux_ra_dispose (demux_plugin_t *this_gen) { if(this->header) free(this->header); + if (this->frame_buffer) + free(this->frame_buffer); free(this); } @@ -333,6 +428,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str this = xine_xmalloc (sizeof (demux_ra_t)); this->stream = stream; this->input = input; + this->frame_buffer = NULL; this->demux_plugin.send_headers = demux_ra_send_headers; this->demux_plugin.send_chunk = demux_ra_send_chunk; diff --git a/src/libreal/xine_real_audio_decoder.c b/src/libreal/xine_real_audio_decoder.c index a90144b95..fe5bca245 100644 --- a/src/libreal/xine_real_audio_decoder.c +++ b/src/libreal/xine_real_audio_decoder.c @@ -218,13 +218,14 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Cook"); if (!load_syms_linux (this, "cook.so", "cook.so.6.0")) return 0; + this->block_align = subpacket_size; break; case BUF_AUDIO_ATRK: _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "Atrac"); if (!load_syms_linux (this, "atrc.so", "atrc.so.6.0")) return 0; - this->block_align = 384; + this->block_align = subpacket_size; break; case BUF_AUDIO_14_4: @@ -352,13 +353,6 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) { return 1; } -static unsigned char sipr_swaps[38][2]={ - {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, - {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, - {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, - {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, - {77,80} }; - static void realdec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { realdec_decoder_t *this = (realdec_decoder_t *) this_gen; @@ -385,116 +379,32 @@ static void realdec_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->pts = buf->pts; size = buf->size; - while (size) { + int need; - int needed; - - needed = this->frame_size - this->frame_num_bytes; - - if (needed>size) { - - memcpy (this->frame_buffer+this->frame_num_bytes, buf->content, size); + need = this->frame_size - this->frame_num_bytes; + if (size < need) { + memcpy (this->frame_buffer + this->frame_num_bytes, + buf->content + buf->size - size, size); this->frame_num_bytes += size; - - lprintf ("buffering %d/%d bytes\n", this->frame_num_bytes, this->frame_size); - size = 0; - } else { - - int result; - int len =-1; - int n; - int sps = this->sps; - int w = this->w; - int h = this->h; audio_buffer_t *audio_buffer; + int n, len; + int result; - lprintf ("buffering %d bytes\n", needed); - - memcpy (this->frame_buffer+this->frame_num_bytes, buf->content, needed); - - size -= needed; + memcpy (this->frame_buffer + this->frame_num_bytes, + buf->content + buf->size - size, need); + size -= need; this->frame_num_bytes = 0; - lprintf ("frame completed. reordering...\n"); - lprintf ("bs=%d sps=%d w=%d h=%d \n",/*sh->wf->nBlockAlign*/-1,sps,w,h); - - if (!sps) { - - int j,n; - int bs=h*w*2/96; /* nibbles per subpacket */ - unsigned char *p=this->frame_buffer; - - /* 'sipr' way */ - /* demux_read_data(sh->ds, p, h*w); */ - for (n=0;n<38;n++){ - int i=bs*sipr_swaps[n][0]; - int o=bs*sipr_swaps[n][1]; - /* swap nibbles of block 'i' with 'o' TODO: optimize */ - for (j=0;j>1)]>>4) : (p[(i>>1)]&15); - int y=(o&1) ? (p[(o>>1)]>>4) : (p[(o>>1)]&15); - if (o&1) - p[(o>>1)]=(p[(o>>1)]&0x0F)|(x<<4); - else - p[(o>>1)]=(p[(o>>1)]&0xF0)|x; - - if (i&1) - p[(i>>1)]=(p[(i>>1)]&0x0F)|(y<<4); - else - p[(i>>1)]=(p[(i>>1)]&0xF0)|y; - - ++i; - ++o; - } - } - /* - sh->a_in_buffer_size= - sh->a_in_buffer_len=w*h; - */ - - } else { - int x, y; - uint8_t *s; - - /* 'cook' way */ - - w /= sps; s = this->frame_buffer; - - for (y=0; y>1))); - - memcpy (this->frame_reordered+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), - s, sps); - s+=sps; - - /* demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), - sps); */ - - } - /* - sh->a_in_buffer_size= - sh->a_in_buffer_len=w*h*sps; - */ - } - -#ifdef LOG - xine_hexdump (this->frame_reordered, buf->size); -#endif - n = 0; - while (nframe_size) { + while (n < this->frame_size) { audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); result = this->raDecode (this->context, - this->frame_reordered+n, + this->frame_buffer + n, this->block_align, (char *) audio_buffer->mem, &len, -1); diff --git a/src/libreal/xine_real_video_decoder.c b/src/libreal/xine_real_video_decoder.c index 57046a5f2..cb7794cca 100644 --- a/src/libreal/xine_real_video_decoder.c +++ b/src/libreal/xine_real_video_decoder.c @@ -551,8 +551,7 @@ void *init_realvdec (xine_t *xine, void *data) { * exported plugin catalog entry */ -static uint32_t supported_types[] = { BUF_VIDEO_RV20, - BUF_VIDEO_RV30, +static uint32_t supported_types[] = { BUF_VIDEO_RV30, BUF_VIDEO_RV40, 0 }; -- cgit v1.2.3 From 3e12aeb9041aaddefad0782921033abbabd9e518 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 7 Apr 2008 17:52:46 +0100 Subject: Check the Real extradata length. --- src/combined/ffmpeg/ff_audio_decoder.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 82b921c8d..3362f7012 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -221,7 +221,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { int version; int data_len; - uint8_t * extradata; + int extradata; version = _X_BE_16 (this->buf+4); if (version == 4) { @@ -229,13 +229,13 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->audio_bits = _X_BE_16 (this->buf+52); this->audio_channels = _X_BE_16 (this->buf+54); data_len = _X_BE_32 (this->buf+67); - extradata = this->buf + 71; + extradata = 71; } else { this->audio_sample_rate = _X_BE_16 (this->buf+54); this->audio_bits = _X_BE_16 (this->buf+58); this->audio_channels = _X_BE_16 (this->buf+60); data_len = _X_BE_32 (this->buf+74); - extradata = this->buf + 78; + extradata = 78; } this->context->block_align = _X_BE_16 (this->buf+44); @@ -244,10 +244,13 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->audio_channels, this->audio_bits, this->audio_sample_rate, this->context->block_align); + if (extradata + data_len > this->size) + break; /* abort early - extradata length is bad */ + this->context->extradata_size = data_len; this->context->extradata = xine_xmalloc(this->context->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - xine_fast_memcpy (this->context->extradata, extradata, + xine_fast_memcpy (this->context->extradata, this->buf + extradata, this->context->extradata_size); break; } -- cgit v1.2.3 From 3cd18fa8a66318366936c50d54e65a8703a66ebd Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 7 Apr 2008 17:54:25 +0100 Subject: Move the sipro codec swap data & code into a common header. --- src/demuxers/Makefile.am | 2 +- src/demuxers/demux_real.c | 35 +++----------------------- src/demuxers/demux_realaudio.c | 31 +++-------------------- src/demuxers/real_common.h | 56 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 src/demuxers/real_common.h (limited to 'src') diff --git a/src/demuxers/Makefile.am b/src/demuxers/Makefile.am index ffbfa0a8d..2c4b38e4a 100644 --- a/src/demuxers/Makefile.am +++ b/src/demuxers/Makefile.am @@ -141,4 +141,4 @@ 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 +noinst_HEADERS = asfheader.h qtpalette.h group_games.h group_audio.h id3.h ebml.h matroska.h iff.h flacutils.h real_common.h diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index f0724a992..cb67c36fa 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -55,6 +55,8 @@ #include "demux.h" #include "bswap.h" +#include "real_common.h" + #define FOURCC_TAG BE_FOURCC #define RMF_TAG FOURCC_TAG('.', 'R', 'M', 'F') #define PROP_TAG FOURCC_TAG('P', 'R', 'O', 'P') @@ -174,13 +176,6 @@ typedef struct { demux_class_t demux_class; } demux_real_class_t; -static const unsigned char sipr_swaps[38][2] = { - {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, - {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, - {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, - {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, - {77,80}}; - static void real_parse_index(demux_real_t *this) { off_t next_index_chunk = this->index_start; @@ -1453,30 +1448,8 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { this->status = DEMUX_FINISHED; return this->status; } - if (spc == sph - 1) { - int n; - int bs = sph * w * 2 / 96; /* nibbles per subpacket */ - /* Perform reordering */ - for(n=0; n < 38; n++) { - int j; - int i = bs * sipr_swaps[n][0]; - int o = bs * sipr_swaps[n][1]; - /* swap nibbles of block 'i' with 'o' TODO: optimize */ - for(j = 0;j < bs; j++) { - int x = (i & 1) ? (buffer[i >> 1] >> 4) : (buffer[i >> 1] & 0x0F); - int y = (o & 1) ? (buffer[o >> 1] >> 4) : (buffer[o >> 1] & 0x0F); - if(o & 1) - buffer[o >> 1] = (buffer[o >> 1] & 0x0F) | (x << 4); - else - buffer[o >> 1] = (buffer[o >> 1] & 0xF0) | x; - if(i & 1) - buffer[i >> 1] = (buffer[i >> 1] & 0x0F) | (y << 4); - else - buffer[i >> 1] = (buffer[i >> 1] & 0xF0) | y; - ++i; ++o; - } - } - } + if (spc == sph - 1) + demux_real_sipro_swap (buffer, sph * w * 2 / 96); break; } if(++this->audio_stream->sub_packet_cnt == sph) { diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c index 2075f1b6f..5bdf13d89 100644 --- a/src/demuxers/demux_realaudio.c +++ b/src/demuxers/demux_realaudio.c @@ -41,6 +41,8 @@ #include "bswap.h" #include "group_audio.h" +#include "real_common.h" + #define RA_FILE_HEADER_PREV_SIZE 22 typedef struct { @@ -74,13 +76,6 @@ typedef struct { demux_class_t demux_class; } demux_ra_class_t; -static const unsigned char sipr_swaps[38][2]={ - {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, - {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, - {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, - {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, - {77,80}}; - /* Map flavour to bytes per second */ static int sipr_fl2bps[4] = {813, 1062, 625, 2000}; // 6.5, 8.5, 5, 16 kbit per second @@ -255,7 +250,6 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { if (this->audio_type == BUF_AUDIO_SIPRO) { int n; int len = this->h * this->w; - int bs = len * 2 / 96; /* nibbles per subpacket */ if(this->input->read(this->input, this->frame_buffer, len) < len) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_realaudio: failed to read audio chunk\n"); @@ -263,26 +257,7 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { this->status = DEMUX_FINISHED; return this->status; } - /* Perform reordering */ - for(n = 0; n < 38; n++) { - int j; - int i = bs * sipr_swaps[n][0]; - int o = bs * sipr_swaps[n][1]; - /* swap nibbles of block 'i' with 'o' TODO: optimize */ - for(j = 0; j < bs; j++) { - int x = (i & 1) ? (this->frame_buffer[i >> 1] >> 4) : (this->frame_buffer[i >> 1] & 0x0F); - int y = (o & 1) ? (this->frame_buffer[o >> 1] >> 4) : (this->frame_buffer[o >> 1] & 0x0F); - if(o & 1) - this->frame_buffer[o >> 1] = (this->frame_buffer[o >> 1] & 0x0F) | (x << 4); - else - this->frame_buffer[o >> 1] = (this->frame_buffer[o >> 1] & 0xF0) | x; - if(i & 1) - this->frame_buffer[i >> 1] = (this->frame_buffer[i >> 1] & 0x0F) | (y << 4); - else - this->frame_buffer[i >> 1] = (this->frame_buffer[i >> 1] & 0xF0) | y; - ++i; ++o; - } - } + demux_real_sipro_swap (this->frame_buffer, len * 2 / 96); } else { int x, y; int pos; diff --git a/src/demuxers/real_common.h b/src/demuxers/real_common.h new file mode 100644 index 000000000..4945a65ff --- /dev/null +++ b/src/demuxers/real_common.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2008 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 + */ + +static inline void demux_real_sipro_swap (char buffer[], int bs) +{ + /* bs = nybbles per subpacket */ + static const unsigned char sipr_swaps[38][2] = { + {0, 63}, {1, 22}, {2, 44}, {3, 90}, {5, 81}, {7, 31}, {8, 86}, {9, 58}, + {10, 36}, {12, 68}, {13, 39}, {14, 73}, {15, 53}, {16, 69}, {17, 57}, + {19, 88}, {20, 34}, {21, 71}, {24, 46}, {25, 94}, {26, 54}, {28, 75}, + {29, 50}, {32, 70}, {33, 92}, {35, 74}, {38, 85}, {40, 56}, {42, 87}, + {43, 65}, {45, 59}, {48, 79}, {49, 93}, {51, 89}, {55, 95}, {61, 76}, + {67, 83}, {77, 80} + }; + int n; + + for (n = 0; n < 38; ++n) + { + int j; + int i = bs * sipr_swaps[n][0]; + int o = bs * sipr_swaps[n][1]; + /* swap nibbles of block 'i' with 'o' TODO: optimize */ + for (j = 0; j < bs; ++j) + { + int x = (i & 1) ? (buffer[i >> 1] >> 4) : (buffer[i >> 1] & 0x0F); + int y = (o & 1) ? (buffer[o >> 1] >> 4) : (buffer[o >> 1] & 0x0F); + if (o & 1) + buffer[o >> 1] = (buffer[o >> 1] & 0x0F) | (x << 4); + else + buffer[o >> 1] = (buffer[o >> 1] & 0xF0) | x; + if (i & 1) + buffer[i >> 1] = (buffer[i >> 1] & 0x0F) | (y << 4); + else + buffer[i >> 1] = (buffer[i >> 1] & 0xF0) | y; + ++i; + ++o; + } + } +} -- cgit v1.2.3 From 7e0dcead623c909ce6dd07995b08b829a9dcfdd5 Mon Sep 17 00:00:00 2001 From: Jinghua Luo Date: Mon, 7 Apr 2008 17:54:41 +0100 Subject: Implement support for "MPEG-3 adu". --- src/combined/ffmpeg/ff_audio_decoder.c | 1 + src/demuxers/demux_real.c | 7 +++++++ src/xine-engine/buffer.h | 1 + src/xine-engine/buffer_types.c | 8 ++++++++ 4 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 3362f7012..d95ae4e0c 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -79,6 +79,7 @@ static const ff_codec_t ff_audio_lookup[] = { {BUF_AUDIO_14_4, CODEC_ID_RA_144, "Real 14.4 (ffmpeg)"}, {BUF_AUDIO_28_8, CODEC_ID_RA_288, "Real 28.8 (ffmpeg)"}, {BUF_AUDIO_MPEG, CODEC_ID_MP3, "MP3 (ffmpeg)"}, + {BUF_AUDIO_MP3ADU, CODEC_ID_MP3ADU, "MPEG-3 adu (ffmpeg)"}, {BUF_AUDIO_MSADPCM, CODEC_ID_ADPCM_MS, "MS ADPCM (ffmpeg)"}, {BUF_AUDIO_QTIMAADPCM, CODEC_ID_ADPCM_IMA_QT, "QT IMA ADPCM (ffmpeg)"}, {BUF_AUDIO_MSIMAADPCM, CODEC_ID_ADPCM_IMA_WAV, "MS IMA ADPCM (ffmpeg)"}, diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index cb67c36fa..fa4e87e07 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -824,6 +824,13 @@ unknown: memcpy(buf->content, mdpr->type_specific_data + 79, buf->decoder_info[2]); + } else if(buf->type == BUF_AUDIO_MP3ADU) { + buf->decoder_flags |= BUF_FLAG_STDHEADER | BUF_FLAG_FRAME_END; + buf->size = 0; + buf->decoder_info[0] = 0; + buf->decoder_info[1] = 0; + buf->decoder_info[2] = 0; + buf->decoder_info[3] = 0; } else { memcpy(buf->content, mdpr->type_specific_data, mdpr->type_specific_len); diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h index 2bcc29510..ebb308a04 100644 --- a/src/xine-engine/buffer.h +++ b/src/xine-engine/buffer.h @@ -258,6 +258,7 @@ extern "C" { #define BUF_AUDIO_SMACKER 0x033B0000 #define BUF_AUDIO_FLVADPCM 0x033C0000 #define BUF_AUDIO_WAVPACK 0x033D0000 +#define BUF_AUDIO_MP3ADU 0x033E0000 /* spu buffer types: */ diff --git a/src/xine-engine/buffer_types.c b/src/xine-engine/buffer_types.c index 7242738e1..26adc1b3c 100644 --- a/src/xine-engine/buffer_types.c +++ b/src/xine-engine/buffer_types.c @@ -804,6 +804,14 @@ static const audio_db_t audio_db[] = { BUF_AUDIO_MPEG, "MPEG layer 2/3" }, +{ + { + ME_FOURCC('a', 'd', 'u', 0x55), + 0 + }, + BUF_AUDIO_MP3ADU, + "MPEG layer-3 adu" +}, { { ME_FOURCC('t','w','o','s'), -- cgit v1.2.3 From d148e35b44f32a6495e7e497c13552b0b89bcc0b Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 7 Apr 2008 17:54:49 +0100 Subject: Shift some audio plugin priorities: swap libreal & ffmpeg, otherwise 7 to 8. --- src/combined/combined_wavpack.c | 2 +- src/combined/ffmpeg/ff_audio_decoder.c | 2 +- src/libmad/xine_mad_decoder.c | 2 +- src/libreal/xine_real_audio_decoder.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/combined/combined_wavpack.c b/src/combined/combined_wavpack.c index 893ee99be..98bbe5b57 100644 --- a/src/combined/combined_wavpack.c +++ b/src/combined/combined_wavpack.c @@ -33,7 +33,7 @@ static uint32_t audio_types[] = { static const decoder_info_t decoder_info_wv = { audio_types, /* supported types */ - 7 /* priority */ + 8 /* priority */ }; const plugin_info_t xine_plugin_info[] EXPORTED = { diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index d95ae4e0c..042900867 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -604,5 +604,5 @@ static uint32_t supported_audio_types[] = { decoder_info_t dec_info_ffmpeg_audio = { supported_audio_types, /* supported types */ - 6 /* priority */ + 7 /* priority */ }; diff --git a/src/libmad/xine_mad_decoder.c b/src/libmad/xine_mad_decoder.c index 46464d23b..021814ca9 100644 --- a/src/libmad/xine_mad_decoder.c +++ b/src/libmad/xine_mad_decoder.c @@ -406,7 +406,7 @@ static uint32_t audio_types[] = { static const decoder_info_t dec_info_audio = { audio_types, /* supported types */ - 7 /* priority */ + 8 /* priority */ }; const plugin_info_t xine_plugin_info[] EXPORTED = { diff --git a/src/libreal/xine_real_audio_decoder.c b/src/libreal/xine_real_audio_decoder.c index fe5bca245..ed3159a84 100644 --- a/src/libreal/xine_real_audio_decoder.c +++ b/src/libreal/xine_real_audio_decoder.c @@ -534,5 +534,5 @@ static uint32_t audio_types[] = { const decoder_info_t dec_info_realaudio = { audio_types, /* supported types */ - 7 /* priority */ + 6 /* priority */ }; -- cgit v1.2.3 From 90dc844d62172741940668ca3ccd2f9472a62ce6 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Mon, 7 Apr 2008 22:53:18 +0200 Subject: Fix vorbis initialization problem in the matroska demuxer due to my last vorbis bugfix. The Vorbis init has to be fixed in a better way, split logic has to be added here, maybe by reusing demux.c code. --- src/demuxers/demux_matroska.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index d081caf61..942a6613e 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -635,9 +635,7 @@ static void init_codec_xiph(demux_matroska_t *this, matroska_track_t *track) { } buf->size = frame[i]; - buf->decoder_flags = BUF_FLAG_HEADER; - if (i == 2) - buf->decoder_flags |= BUF_FLAG_FRAME_END; + buf->decoder_flags = BUF_FLAG_HEADER | BUF_FLAG_FRAME_START | BUF_FLAG_FRAME_END; buf->type = track->buf_type; buf->pts = 0; -- cgit v1.2.3 From 964f55aef546a1f1574c9f6ec10b3410fe390c34 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 8 Apr 2008 00:08:20 +0100 Subject: Fix YUY2 Video Output on Mac OS X XineOpenGLView For YUY2, twice the amount of data was copied into texture_buffer leading to a segfault. The crash happened with visualizers such as GOOM and oscope but not for normal video. --- src/video_out/video_out_macosx.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/video_out/video_out_macosx.m b/src/video_out/video_out_macosx.m index 4621d31b9..a13de239f 100644 --- a/src/video_out/video_out_macosx.m +++ b/src/video_out/video_out_macosx.m @@ -207,7 +207,7 @@ static void macosx_display_frame(vo_driver_t *vo_driver, vo_frame_t *vo_frame) { break; case XINE_IMGFMT_YUY2: xine_fast_memcpy (texture_buffer, vo_frame->base[0], - vo_frame->pitches[0] * vo_frame->height * 2); + vo_frame->pitches[0] * vo_frame->height); [driver->view updateTexture]; break; default: -- cgit v1.2.3